teiid SVN: r1211 - in trunk: engine/src/main/java/com/metamatrix/query/optimizer/relational/rules and 3 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-31 11:42:46 -0400 (Fri, 31 Jul 2009)
New Revision: 1211
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java
trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java
Log:
TEIID-339 expanding and correcting the check to use all rows and making the condition to push distinct stricter.
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml 2009-07-31 15:42:46 UTC (rev 1211)
@@ -214,7 +214,7 @@
<sect2>
<title>Partial Aggregate Pushdown</title>
<para> Partial aggregate pushdown allows for grouping operations
- above multi-source joins to be decomposed so that some of the
+ above multi-source joins and unions to be decomposed so that some of the
grouping and aggregate functions may be pushed down to the
sources.</para>
</sect2>
@@ -239,10 +239,13 @@
</para>
<programlisting>select a.column1 from a</programlisting>
<tip>
- <para> When a join clause is omitted, the relevant join criteria
+ <para>When a join clause is omitted via the optional join hint, the relevant join criteria
is not applied. Thus it is possible that the query results may
not have the same cardinality or even the same row values as
when the join is fully applied.</para>
+ <para>Left/right outer joins where the inner side values are not used
+ and whose rows under go a distinct operation will automatically be
+ treated as an optional join and does not require a hint.</para>
</tip>
</sect2>
<sect2 id="standard_relational_techniques">
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/NewCalculateCostUtil.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -87,8 +87,8 @@
// the following variables are used to hold cost estimates (roughly in milliseconds)
private final static float compareTime = .05f; //TODO: a better estimate would be based upon the number of conjuncts
private final static float readTime = .001f;
- private final static float procNewRequestTime = 100;
- private final static float procMoreRequestTime = 15;
+ private final static float procNewRequestTime = 100; //TODO: should come from the connector
+ private final static float procMoreRequestTime = 15; //TODO: should come from the connector
/**
* Calculate cost of a node and all children, recursively from the bottom up.
@@ -100,10 +100,18 @@
*/
static float computeCostForTree(PlanNode node, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
-
- recursiveComputeCost(node, metadata);
-
+
Float cost = (Float) node.getProperty(NodeConstants.Info.EST_CARDINALITY);
+
+ // check if already computed
+ if(cost == null) {
+ for (PlanNode child : node.getChildren()) {
+ computeCostForTree(child, metadata);
+ }
+ computeNodeCost(node, metadata);
+ cost = (Float) node.getProperty(NodeConstants.Info.EST_CARDINALITY);
+ }
+
if(cost != null) {
return cost.floatValue();
}
@@ -112,38 +120,12 @@
}
/**
- * This method recursively estimates, from the bottom up, the cost of each node in
- * the plan subtree. If a cost can't be estimated for any node, the whole recursive
- * operation is aborted.
+ * This method attempts to estimate a cost for each type of node.
* @param node
* @param metadata
* @throws QueryMetadataException
* @throws MetaMatrixComponentException
*/
- private static void recursiveComputeCost(PlanNode node, QueryMetadataInterface metadata)
- throws QueryMetadataException, MetaMatrixComponentException {
-
- // check if already computed
- if(node.getProperty(NodeConstants.Info.EST_CARDINALITY) != null) {
- return;
- }
-
- Iterator children = node.getChildren().iterator();
- while (children.hasNext()) {
- PlanNode child = (PlanNode)children.next();
- recursiveComputeCost(child, metadata);
- }
- computeNodeCost(node, metadata);
- }
-
- /**
- * This method attempts to estimate a cost for each type of node
- * that can be below an access node at this podouble in planning.
- * @param node
- * @param metadata
- * @throws QueryMetadataException
- * @throws MetaMatrixComponentException
- */
private static void computeNodeCost(PlanNode node, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
@@ -182,11 +164,10 @@
case NodeConstants.Types.PROJECT:
{
- PlanNode child = null;
Float childCost = null;
//Simply record the cost of the only child
if (node.getChildCount() != 0) {
- child = node.getFirstChild();
+ PlanNode child = node.getFirstChild();
childCost = (Float)child.getProperty(NodeConstants.Info.EST_CARDINALITY);
} else {
childCost = new Float(1);
@@ -210,7 +191,9 @@
// All rows will be projected so add both costs together.
cost += childCost1;
}
- cost = getDistinctEstimate(node, metadata, cost);
+ if (!node.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
+ cost = getDistinctEstimate(node, metadata, cost);
+ }
} else {
float leftCost = (Float)node.getFirstChild().getProperty(NodeConstants.Info.EST_CARDINALITY);
leftCost = getDistinctEstimate(node.getFirstChild(), metadata, leftCost);
@@ -279,11 +262,10 @@
}
private static void setCardinalityEstimate(PlanNode node, Float bestEstimate) {
- if (bestEstimate != null){
- node.setProperty(NodeConstants.Info.EST_CARDINALITY, bestEstimate);
- } else {
- node.setProperty(NodeConstants.Info.EST_CARDINALITY, new Float(UNKNOWN_VALUE));
+ if (bestEstimate == null){
+ bestEstimate = Float.valueOf(UNKNOWN_VALUE);
}
+ node.setProperty(NodeConstants.Info.EST_CARDINALITY, bestEstimate);
}
/**
@@ -559,8 +541,7 @@
private static float estimatePredicateCost(float childCost, PlanNode currentNode, PredicateCriteria predicateCriteria, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
- HashSet elements = new HashSet();
- ElementCollectorVisitor.getElements(predicateCriteria, elements);
+ Collection<ElementSymbol> elements = ElementCollectorVisitor.getElements(predicateCriteria, true);
Collection groups = GroupsUsedByElementsVisitor.getGroups(predicateCriteria);
boolean multiGroup = groups.size() > 1;
@@ -787,7 +768,7 @@
return cost;
}
- static boolean usesKey(Collection<SingleElementSymbol> allElements, QueryMetadataInterface metadata)
+ static boolean usesKey(Collection<? extends SingleElementSymbol> allElements, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
if(allElements == null || allElements.size() == 0) {
@@ -796,9 +777,7 @@
// Sort elements into groups
Map groupMap = new HashMap();
- Iterator elementIter = allElements.iterator();
- while(elementIter.hasNext()) {
- SingleElementSymbol ses = (SingleElementSymbol) elementIter.next();
+ for (SingleElementSymbol ses : allElements) {
if (!(ses instanceof ElementSymbol)) {
continue;
}
@@ -842,7 +821,7 @@
* @return
* @since 4.3
*/
- private static float getCardinality(HashSet elements, QueryMetadataInterface metadata)
+ private static float getCardinality(Collection elements, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
if(elements.size() != 1) {
@@ -879,7 +858,7 @@
* @return
* @since 4.3
*/
- private static boolean isNullable(HashSet elements, QueryMetadataInterface metadata)
+ private static boolean isNullable(Collection elements, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
if(elements.size() != 1) {
@@ -896,7 +875,7 @@
* @return
* @since 4.3
*/
- private static float getNNV(HashSet elements, QueryMetadataInterface metadata)
+ private static float getNNV(Collection elements, QueryMetadataInterface metadata)
throws QueryMetadataException, MetaMatrixComponentException {
if(elements.size() != 1) {
@@ -1019,7 +998,7 @@
independentNode.setProperty(NodeConstants.Info.EST_SET_SIZE, new Float(indSymbolNDV));
- //for non-partitioned joins the cardinatlity of the dependentaccess should never be greater than the dependent cardinality
+ //for non-partitioned joins the cardinality of the dependentaccess should never be greater than the dependent cardinality
//TODO: when partitioned joins are implemented, this logic will need updated
float dependentAccessCardinality = Math.min(dependentCardinality, dependentCardinality * indSymbolNDV / depSymbolNDV);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleCollapseSource.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -29,6 +29,7 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryPlannerException;
+import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.analysis.AnalysisRecord;
import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
@@ -96,7 +97,7 @@
}
plan = removeUnnecessaryInlineView(plan, commandRoot);
QueryCommand queryCommand = createQuery(metadata, capFinder, accessNode, commandRoot);
- addSetOpDistinct(metadata, capFinder, accessNode, queryCommand);
+ addDistinct(metadata, capFinder, accessNode, queryCommand);
command = queryCommand;
if (intoGroup != null) {
Insert insertCommand = new Insert(intoGroup, ResolverUtil.resolveElementsInGroup(intoGroup, metadata), null);
@@ -112,29 +113,55 @@
return plan;
}
- private void addSetOpDistinct(QueryMetadataInterface metadata,
+ /**
+ * This functions as "RulePushDistinct", however we do not bother
+ * checking to see if a parent dup removal can actually be removed
+ * - which can only happen if there are sources/selects/simple projects/limits/order by
+ * between the access node and the parent dup removal.
+ *
+ * @param metadata
+ * @param capFinder
+ * @param accessNode
+ * @param queryCommand
+ * @throws QueryMetadataException
+ * @throws MetaMatrixComponentException
+ */
+ private void addDistinct(QueryMetadataInterface metadata,
CapabilitiesFinder capFinder, PlanNode accessNode,
QueryCommand queryCommand) throws QueryMetadataException,
MetaMatrixComponentException {
- if (queryCommand.getLimit() != null && queryCommand.getOrderBy() != null) {
+ if (queryCommand.getLimit() != null) {
return; //TODO: could create an inline view
}
- PlanNode parent = accessNode.getParent();
- boolean dupRemoval = false;
- while (parent != null && parent.getType() == NodeConstants.Types.SET_OP) {
- if (!parent.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
- dupRemoval = true;
- }
- parent = parent.getParent();
+ if (queryCommand.getOrderBy() == null) {
+ /*
+ * we're assuming that a pushed order by implies that the cost of the distinct operation
+ * will be marginal - which is not always true.
+ *
+ * TODO: we should add costing for the benefit of pushing distinct by itself
+ * cardinality without = c
+ * assume cost ~ c lg c for c' cardinality and a modification for associated bandwidth savings
+ * recompute cost of processing plan with c' and see if new cost + c lg c < original cost
+ */
+ return;
}
- if (!dupRemoval || NewCalculateCostUtil.usesKey(queryCommand.getProjectedSymbols(), metadata)) {
+ if (RuleRemoveOptionalJoins.useNonDistinctRows(accessNode.getParent())) {
return;
}
- //TODO: we should also order the results and update the set processing logic
- // this requires that we can guarantee null ordering
+ // ensure that all columns are comparable - they might not be if there is an intermediate project
+ for (SingleElementSymbol ses : queryCommand.getProjectedSymbols()) {
+ if (DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(ses.getType()))) {
+ return;
+ }
+ }
+ /*
+ * TODO: if we are under a grouping/union not-all, then we should also fully order the results
+ * and update the processing logic (this requires that we can guarantee null ordering) to assume sorted
+ */
if (queryCommand instanceof SetQuery) {
((SetQuery)queryCommand).setAll(false);
- } else if (CapabilitiesUtil.supports(Capability.QUERY_SELECT_DISTINCT, RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder)) {
+ } else if (!NewCalculateCostUtil.usesKey(queryCommand.getProjectedSymbols(), metadata) && CapabilitiesUtil.supports(Capability.QUERY_SELECT_DISTINCT, RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder)) {
+ //TODO: could check for group by and a select clause containing all group by expressions
((Query)queryCommand).getSelect().setDistinct(true);
}
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -129,8 +129,7 @@
PlanNode sortNode = createSortNode(orderSymbols, outputSymbols, directions);
if (sourceNode.getType() == NodeConstants.Types.ACCESS) {
- if (NodeEditor.findAllNodes(sourceNode, NodeConstants.Types.SOURCE).size() == 1
- && NewCalculateCostUtil.usesKey(expressions, metadata)) {
+ if (NewCalculateCostUtil.usesKey(expressions, metadata)) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
}
if (attemptPush && RuleRaiseAccess.canRaiseOverSort(sourceNode, metadata, capFinder, sortNode)) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RulePushAggregates.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -175,15 +175,7 @@
}
//check to see if any aggregate is dependent upon cardinality
- boolean cardinalityDependent = false;
- for (AggregateSymbol aggregateSymbol : aggregates) {
- if (aggregateSymbol.getAggregateFunction().equals(ReservedWords.COUNT)
- || aggregateSymbol.getAggregateFunction().equals(ReservedWords.AVG)
- || aggregateSymbol.getAggregateFunction().equals(ReservedWords.SUM)) {
- cardinalityDependent = true;
- break;
- }
- }
+ boolean cardinalityDependent = RuleRemoveOptionalJoins.areAggregatesCardinalityDependent(aggregates);
LinkedList<PlanNode> unionChildren = new LinkedList<PlanNode>();
findUnionChildren(unionChildren, cardinalityDependent, setOp);
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -217,7 +217,7 @@
JoinType jt = (JoinType)joinNode.getProperty(NodeConstants.Info.JOIN_TYPE);
if (!optionalNode.hasBooleanProperty(NodeConstants.Info.IS_OPTIONAL) &&
- !(jt == JoinType.JOIN_LEFT_OUTER && optionalNode == joinNode.getLastChild() && isDistinct(joinNode.getParent()))) {
+ (jt != JoinType.JOIN_LEFT_OUTER || optionalNode != joinNode.getLastChild() || useNonDistinctRows(joinNode.getParent()))) {
return false;
}
// remove the parent node and move the sibling node upward
@@ -242,31 +242,41 @@
* Ensure that the needed elements come only from the left hand side and
* that cardinality won't matter
*/
- private boolean isDistinct(PlanNode parent) {
+ static boolean useNonDistinctRows(PlanNode parent) {
while (parent != null) {
switch (parent.getType()) {
case NodeConstants.Types.DUP_REMOVE: {
- return true;
+ return false;
}
case NodeConstants.Types.SET_OP: {
if (!parent.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
- return true;
+ return false;
}
break;
}
case NodeConstants.Types.GROUP: {
Set<AggregateSymbol> aggs = RulePushAggregates.collectAggregates(parent);
- for (AggregateSymbol aggregateSymbol : aggs) {
- if (aggregateSymbol.getAggregateFunction().equalsIgnoreCase(ReservedWords.COUNT) ||
- aggregateSymbol.getAggregateFunction().equalsIgnoreCase(ReservedWords.AVG)) {
- return false;
- }
+ return areAggregatesCardinalityDependent(aggs);
+ }
+ case NodeConstants.Types.TUPLE_LIMIT: {
+ if (parent.getFirstChild().getType() == NodeConstants.Types.SORT) {
+ return true;
}
- return true;
}
+ //we assmue that projects of non-deterministic expressions do not matter
}
parent = parent.getParent();
}
+ return true;
+ }
+
+ static boolean areAggregatesCardinalityDependent(Set<AggregateSymbol> aggs) {
+ for (AggregateSymbol aggregateSymbol : aggs) {
+ if (aggregateSymbol.getAggregateFunction().equalsIgnoreCase(ReservedWords.COUNT) ||
+ aggregateSymbol.getAggregateFunction().equalsIgnoreCase(ReservedWords.AVG)) {
+ return true;
+ }
+ }
return false;
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestAggregatePushdown.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -205,7 +205,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
metadata,
null, getAggregatesFinder(),
- new String[] {"SELECT g_0.p_productid AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, SUM(g_0.o_amount) AS c_2 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT DISTINCT g_0.p_productid AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT DISTINCT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, SUM(g_0.o_amount) AS c_2 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
TestOptimizer.checkNodeTypes(plan, new int[] {
@@ -235,7 +235,7 @@
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
metadata,
null, getAggregatesFinder(),
- new String[] {"SELECT g_0.p_productid AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, MAX(g_0.o_amount) AS c_2, SUM(g_0.o_amount) AS c_3 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT DISTINCT g_0.p_productid AS c_0 FROM m2.product AS g_0 WHERE g_0.p_divid = 100 ORDER BY c_0", "SELECT DISTINCT g_0.o_productid AS c_0, g_0.o_dealerid AS c_1, MAX(g_0.o_amount) AS c_2, SUM(g_0.o_amount) AS c_3 FROM m1.\"order\" AS g_0, m1.dealer AS g_1 WHERE (g_0.o_dealerid = g_1.d_dealerid) AND (g_1.d_state = 'CA') AND (g_0.o_productid IN (<dependent values>)) GROUP BY g_0.o_productid, g_0.o_dealerid ORDER BY c_0"}, //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING );
TestOptimizer.checkNodeTypes(plan, new int[] {
@@ -570,7 +570,7 @@
metadata,
null, capFinder,
new String[] {"SELECT g_0.MONTH, g_0.YEAR FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999'", //$NON-NLS-1$
- "SELECT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
+ "SELECT DISTINCT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
"SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING );
@@ -618,7 +618,7 @@
metadata,
null, capFinder,
new String[] {"SELECT g_0.MONTH, g_0.YEAR FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999'", //$NON-NLS-1$
- "SELECT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
+ "SELECT DISTINCT g_0.MONTH AS c_0, g_0.CITY AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0 WHERE (g_0.MONTH IN (<dependent values>)) AND (g_0.CITY IN (<dependent values>)) GROUP BY g_0.MONTH, g_0.CITY ORDER BY c_0, c_1", //$NON-NLS-1$
"SELECT g_0.CITY, g_0.REGION FROM oraclemodel.GEOGRAPHY AS g_0 WHERE g_0.REGION IN ('BORDEAUX', 'POLINESIA')"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING );
@@ -665,7 +665,7 @@
ProcessorPlan plan = helpPlan(sql,
metadata,
null, capFinder,
- new String[] {"SELECT g_0.MONTH AS c_0, g_1.REGION AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0, db2model.GEOGRAPHY2 AS g_1 WHERE (g_0.CITY = g_1.CITY) AND (g_1.REGION IN ('BORDEAUX', 'POLINESIA')) AND (g_0.MONTH IN (<dependent values>)) GROUP BY g_0.MONTH, g_1.REGION ORDER BY c_0", //$NON-NLS-1$
+ new String[] {"SELECT DISTINCT g_0.MONTH AS c_0, g_1.REGION AS c_1, SUM(g_0.SALES) AS c_2 FROM db2model.SALES AS g_0, db2model.GEOGRAPHY2 AS g_1 WHERE (g_0.CITY = g_1.CITY) AND (g_1.REGION IN ('BORDEAUX', 'POLINESIA')) AND (g_0.MONTH IN (<dependent values>)) GROUP BY g_0.MONTH, g_1.REGION ORDER BY c_0", //$NON-NLS-1$
"SELECT g_0.MONTH AS c_0, g_0.YEAR AS c_1 FROM msModel.\"TIME\" AS g_0 WHERE g_0.YEAR = '1999' ORDER BY c_0"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING );
@@ -709,7 +709,7 @@
metadata,
null, capFinder,
new String[] {"SELECT c2, c1, c0 FROM db2model.DB2TABLE", //$NON-NLS-1$
- "SELECT b2, sum(b0) FROM oraclemodel.OraTable GROUP BY b2 ORDER BY b2"}, //$NON-NLS-1$
+ "SELECT DISTINCT b2, sum(b0) FROM oraclemodel.OraTable GROUP BY b2 ORDER BY b2"}, //$NON-NLS-1$
SHOULD_SUCCEED );
checkNodeTypes(plan, new int[] {
@@ -791,8 +791,8 @@
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan("select count(e2) from (select e1, e2 from pm1.g1 union select e1, e2 from pm1.g2) z", FakeMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$
- new String[]{"SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", //$NON-NLS-1$
- "SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ new String[]{"SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", //$NON-NLS-1$
+ "SELECT g_0.e1, g_0.e2 FROM pm1.g1 AS g_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
0, // DependentAccess
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptimizer.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -902,28 +902,28 @@
public void testPushingCriteriaThroughUnion1() {
helpPlan("select e1 from vm1.u1 where e1='abc'", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE pm1.g3.e1 = 'abc'", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+ "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
}
public void testPushingCriteriaThroughUnion2() {
helpPlan("select e1 from vm1.u2 where e1='abc'", example1(), //$NON-NLS-1$
- new String[] { "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+ new String[] { "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
}
public void testPushingCriteriaThroughUnion3() {
helpPlan("select e1 from vm1.u1 where e1='abc' and e2=5", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE (pm1.g3.e1 = 'abc') AND (pm1.g3.e2 = 5)", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') AND (pm1.g2.e2 = 5)", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') AND (pm1.g1.e2 = 5)" } ); //$NON-NLS-1$
+ "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') AND (pm1.g2.e2 = 5)", //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') AND (pm1.g1.e2 = 5)" } ); //$NON-NLS-1$
}
public void testPushingCriteriaThroughUnion4() {
helpPlan("select e1 from vm1.u1 where e1='abc' or e2=5", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE (pm1.g3.e1 = 'abc') OR (pm1.g3.e2 = 5)", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e2 = 5)", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') OR (pm1.g2.e2 = 5)" } ); //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE (pm1.g1.e1 = 'abc') OR (pm1.g1.e2 = 5)", //$NON-NLS-1$
+ "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE (pm1.g2.e1 = 'abc') OR (pm1.g2.e2 = 5)" } ); //$NON-NLS-1$
}
// expression in a subquery of the union
@@ -992,8 +992,8 @@
ProcessorPlan plan = helpPlan("select vm1.u1.e1 from vm1.u1, pm1.g1 where vm1.u1.e1='abc' and vm1.u1.e1=pm1.g1.e1", example1(), //$NON-NLS-1$
new String[] { "SELECT pm1.g1.e1 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'", //$NON-NLS-1$
"SELECT pm1.g3.e1, pm1.g3.e2, pm1.g3.e3, pm1.g3.e4 FROM pm1.g3 WHERE pm1.g3.e1 = 'abc'", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
+ "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2 WHERE pm1.g2.e1 = 'abc'", //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 WHERE pm1.g1.e1 = 'abc'" } ); //$NON-NLS-1$
checkNodeTypes(plan, new int[] {
4, // Access
0, // DependentAccess
@@ -1137,8 +1137,8 @@
public void testDefect5283() {
helpPlan("select * from vm1.a6", example1(), //$NON-NLS-1$
- new String[] { "SELECT DISTINCT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", //$NON-NLS-1$
- "SELECT DISTINCT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2" } ); //$NON-NLS-1$
+ new String[] { "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", //$NON-NLS-1$
+ "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM pm1.g2" } ); //$NON-NLS-1$
}
public void testManyJoinsOverThreshold() throws Exception {
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestOptionalJoins.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -22,15 +22,15 @@
package com.metamatrix.query.optimizer;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.metamatrix.query.optimizer.TestOptimizer.ComparisonMode;
import com.metamatrix.query.processor.ProcessorPlan;
import com.metamatrix.query.unittest.FakeMetadataFactory;
-public class TestOptionalJoins extends TestCase {
+public class TestOptionalJoins {
- public void testOptionalJoinNode1() {
+ @Test public void testOptionalJoinNode1() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -39,7 +39,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode1_1() {
+ @Test public void testOptionalJoinNode1_1() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1,pm2.g2.e1 FROM pm1.g1, /* optional */ pm2.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm2.g2.e1 FROM pm2.g2"} ); //$NON-NLS-1$//$NON-NLS-2$
@@ -63,21 +63,21 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode2() {
+ @Test public void testOptionalJoinNode2() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1, /* optional */ pm1.g2, pm1.g3", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g3 AS g_1"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode3() {
+ @Test public void testOptionalJoinNode3() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode3_1() {
+ @Test public void testOptionalJoinNode3_1() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1, pm2.g2.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm2.g2 on pm1.g1.e1 = pm2.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT g_0.e1 AS c_0 FROM pm2.g2 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0"} ); //$NON-NLS-1$ //$NON-NLS-2$
@@ -101,49 +101,49 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode4() {
+ @Test public void testOptionalJoinNode4() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode5() {
+ @Test public void testOptionalJoinNode5() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN /* optional */ pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g2 AS g_1 ON g_0.e1 = g_1.e1"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode6() {
+ @Test public void testOptionalJoinNode6() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM (pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g3 AS g_1 ON g_0.e1 = g_1.e1"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode7() {
+ @Test public void testOptionalJoinNode7() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN pm1.g2 on pm1.g1.e1 = pm1.g2.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g3.e1 FROM pm1.g3"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode8() {
+ @Test public void testOptionalJoinNode8() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ (select * from pm1.g2) as X on pm1.g1.e1 = x.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode9() {
+ @Test public void testOptionalJoinNode9() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g2.e1 FROM pm1.g2, /* optional */ vm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g2.e1 FROM pm1.g2"} ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinNode10() {
+ @Test public void testOptionalJoinNode10() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM /* optional */ vm1.g1, pm1.g1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -152,7 +152,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode11() {
+ @Test public void testOptionalJoinNode11() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g1.e1 FROM pm1.g1 LEFT OUTER JOIN /* optional */ vm1.g2 on pm1.g1.e1 = vm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -161,7 +161,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode12() {
+ @Test public void testOptionalJoinNode12() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM /* optional */ (pm1.g1 LEFT OUTER JOIN vm1.g1 on pm1.g1.e1 = vm1.g1.e1) LEFT OUTER JOIN pm1.g3 on pm1.g1.e1 = pm1.g3.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g3.e1 FROM pm1.g3"} ); //$NON-NLS-1$
@@ -170,7 +170,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode13() {
+ @Test public void testOptionalJoinNode13() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT count(pm1.g1.e1) FROM pm1.g1 LEFT OUTER JOIN /* optional */ pm1.g2 on pm1.g1.e1 = pm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -197,9 +197,9 @@
/**
* The distinct prevents the removal of the optional join
*/
- public void testOptionalJoinNode14() throws Exception {
+ @Test public void testOptionalJoinNode14() throws Exception {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT ve1 FROM vm1.g4", FakeMetadataFactory.example4(), //$NON-NLS-1$
- new String[] {"SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0", "SELECT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 ORDER BY c_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0", "SELECT DISTINCT g_0.e1 AS c_0 FROM pm1.g2 AS g_0 ORDER BY c_0"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
1, // Access
@@ -221,7 +221,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode15() {
+ @Test public void testOptionalJoinNode15() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT x.e1 FROM (select vm1.g1.e1, vm1.g2.e2 from vm1.g1 LEFT OUTER JOIN /* optional */vm1.g2 on vm1.g1.e2 = vm1.g2.e2) AS x", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g1.e1 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -230,7 +230,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode16() {
+ @Test public void testOptionalJoinNode16() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT length(z) FROM /* optional */ pm1.g1, (select distinct e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY y, z) AS x", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT e2, e3 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -254,7 +254,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinNode17() {
+ @Test public void testOptionalJoinNode17() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT length(z) FROM /* optional */ pm1.g1 inner join (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x on pm1.g1.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT e3 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -278,16 +278,16 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinWithIntersection() throws Exception {
+ @Test public void testOptionalJoinWithIntersection() throws Exception {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM pm1.g3 inner join (select pm1.g1.e2 as y from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1) AS x on pm1.g3.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT g_0.e1 FROM pm1.g3 AS g_0, pm1.g1 AS g_1, pm1.g2 AS g_2 WHERE (g_1.e1 = g_2.e1) AND (g_0.e2 = g_1.e2)"}, ComparisonMode.EXACT_COMMAND_STRING ); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinWithNestedOrderBy() {
+ @Test public void testOptionalJoinWithNestedOrderBy() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM pm1.g3 inner join (select pm1.g2.e1, pm1.g1.e2 as y from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1 order by pm1.g2.e1 limit 10000) AS x on pm1.g3.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
- new String[] {"SELECT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm1.g3 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0, g_1.e1 AS c_1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 = g_1.e1 ORDER BY c_1"} ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new String[] {"SELECT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm1.g3 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0, g_1.e1 AS c_1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 = g_1.e1 ORDER BY c_1"} ); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
@@ -312,7 +312,7 @@
/**
* Grouping will prevent the removal from happening
*/
- public void testOptionalJoinWithGroupingOverAllColumns() {
+ @Test public void testOptionalJoinWithGroupingOverAllColumns() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT pm1.g3.e1 FROM pm1.g3, (select max(pm1.g1.e4) y from /* optional */ pm1.g1, pm1.g2 where pm1.g1.e1 = pm1.g2.e1) AS x where pm1.g3.e2=x.y", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT g_0.e2, g_0.e1 FROM pm1.g3 AS g_0", "SELECT g_0.e4 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE g_0.e1 = g_1.e1"} ); //$NON-NLS-1$ //$NON-NLS-2$
@@ -339,7 +339,7 @@
/**
* Union should prevent the removal from happening
*/
- public void testOptionalJoinWithUnion() {
+ @Test public void testOptionalJoinWithUnion() {
ProcessorPlan plan = TestOptimizer.helpPlan("select pm1.g2.e4 from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1 union all select convert(pm1.g2.e2, double) from /* optional */ pm1.g1 inner join pm1.g2 on pm1.g1.e1 = pm1.g2.e1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT pm1.g2.e4 FROM pm1.g2", "SELECT pm1.g2.e2 FROM pm1.g2"} ); //$NON-NLS-1$ //$NON-NLS-2$
@@ -363,7 +363,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinWithCompoundCriteria() {
+ @Test public void testOptionalJoinWithCompoundCriteria() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT length(z) FROM /* optional */ pm1.g1 inner join (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x on pm1.g1.e2=x.y and concat(x.y, x.z) = '1'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] {"SELECT e3 FROM pm1.g1"} ); //$NON-NLS-1$
@@ -387,9 +387,9 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinWithDupRemoval() {
+ @Test public void testOptionalJoinWithDupRemoval() {
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT a.e1 from (SELECT distinct pm1.g1.e1, x.y FROM pm1.g1, /* optional */ (select e2 as y, e3 || 'x' as z from pm1.g1 ORDER BY z) AS x where pm1.g1.e2=x.y) as a", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
- new String[] {"SELECT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"} ); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] {"SELECT DISTINCT g_0.e2 AS c_0 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT DISTINCT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"} ); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
@@ -415,7 +415,7 @@
* Cross Joins do not allow for join removal
* This could be optimized though as an exists predicate
*/
- public void testOptionalJoinWithoutHint_crossJoin() {
+ @Test public void testOptionalJoinWithoutHint_crossJoin() {
ProcessorPlan plan = TestOptimizer
.helpPlan(
"SELECT distinct pm1.g1.e1 from pm1.g1, pm1.g2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
@@ -424,7 +424,7 @@
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinWithoutHint_outerJoin() {
+ @Test public void testOptionalJoinWithoutHint_outerJoin() {
ProcessorPlan plan = TestOptimizer
.helpPlan(
"SELECT distinct pm1.g1.e2 from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1)", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
@@ -433,7 +433,7 @@
TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- public void testOptionalJoinWithoutHint_aggregate() {
+ @Test public void testOptionalJoinWithoutHint_aggregate() {
ProcessorPlan plan = TestOptimizer
.helpPlan(
"SELECT pm1.g1.e3, max(pm1.g1.e2) from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) group by pm1.g1.e3", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
@@ -462,7 +462,7 @@
/**
* The average agg will prevent the join removal
*/
- public void testOptionalJoinWithoutHint_aggregate1() {
+ @Test public void testOptionalJoinWithoutHint_aggregate1() {
ProcessorPlan plan = TestOptimizer
.helpPlan(
"SELECT pm1.g1.e3, avg(pm1.g1.e2) from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) group by pm1.g1.e3", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
@@ -488,7 +488,7 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
- public void testOptionalJoinWithoutHint_union() {
+ @Test public void testOptionalJoinWithoutHint_union() {
ProcessorPlan plan = TestOptimizer
.helpPlan(
"SELECT pm1.g1.e3 from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) union select 1", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
@@ -514,4 +514,30 @@
TestOptimizer.checkSubPlanCount(plan, 0);
}
+ @Test public void testOptionalJoinWithOrderedLimit() {
+ ProcessorPlan plan = TestOptimizer
+ .helpPlan(
+ "select distinct * from (SELECT pm1.g1.e3 from pm1.g1 left outer join pm1.g2 on (pm1.g1.e1 = pm1.g2.e1) order by e3 limit 10) x", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
+ new String[] { "SELECT DISTINCT g_0.e3 AS c_0 FROM pm1.g1 AS g_0 LEFT OUTER JOIN pm1.g2 AS g_1 ON g_0.e1 = g_1.e1 ORDER BY c_0" }); //$NON-NLS-1$
+
+ TestOptimizer.checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 1, // DupRemove
+ 0, // Grouping
+ 0, // Join
+ 0, // MergeJoin
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+
+ TestOptimizer.checkSubPlanCount(plan, 0);
+ }
+
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestStoredProcedurePlanning.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -298,7 +298,7 @@
public void testStoredQuery22() {
ProcessorPlan plan = TestOptimizer.helpPlan("select e1 from (EXEC pm1.sq1()) as x where e1='a' union (select e1 from vm1.g2 where e1='b')", new TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()), //$NON-NLS-1$
- new String[] { "SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", "SELECT DISTINCT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = 'b') AND (g_1.e1 = 'b')" }); //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", "SELECT g_0.e1 FROM pm1.g1 AS g_0, pm1.g2 AS g_1 WHERE (g_0.e1 = g_1.e1) AND (g_0.e1 = 'b') AND (g_1.e1 = 'b')" }); //$NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
Modified: trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/optimizer/TestUnionPlanning.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -73,7 +73,7 @@
capFinder.addCapabilities("BQT2", caps); //$NON-NLS-1$
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT IntKey FROM BQT1.SmallA UNION SELECT IntNum FROM BQT2.SmallA UNION ALL SELECT IntNum FROM BQT1.SmallA", FakeMetadataFactory.exampleBQTCached(), null, capFinder,//$NON-NLS-1$
- new String[] { "SELECT DISTINCT IntNum FROM BQT2.SmallA", "SELECT DISTINCT IntKey FROM BQT1.SmallA", "SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ new String[] { "SELECT IntNum FROM BQT2.SmallA", "SELECT IntKey FROM BQT1.SmallA", "SELECT IntNum FROM BQT1.SmallA" }, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TestOptimizer.checkNodeTypes(plan, new int[] {
3, // Access
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestSetProcessing.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -35,7 +35,7 @@
public void testExcept() {
String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2"; //$NON-NLS-1$
- ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
List<?>[] expected = new List[] {
Arrays.asList(new Object[] {"a", 0}), //$NON-NLS-1$
@@ -51,7 +51,7 @@
public void testIntersect() {
String sql = "select e1, e2 from pm1.g2 intersect select e1, 1 from pm1.g2"; //$NON-NLS-1$
- ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$
List<?>[] expected = new List[] {
Arrays.asList(new Object[] {null, 1}),
@@ -66,7 +66,7 @@
public void testIntersectExcept() {
String sql = "select e1, e2 from pm1.g2 except select e1, 1 from pm1.g2 intersect select 'a', e2 from pm1.g2"; //$NON-NLS-1$
- ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT DISTINCT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g2 AS g_0", "SELECT g_0.e1, g_0.e2 FROM pm1.g2 AS g_0", "SELECT g_0.e2 FROM pm1.g2 AS g_0"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
List<?>[] expected = new List[] {
Arrays.asList(new Object[] {null, 1}),
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestVirtualDepJoin.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -391,8 +391,8 @@
List<String> expectedQueries = new ArrayList<String>(6);
for (int i = 0; i < 3; i++) {
- expectedQueries.add("SELECT g_0.id AS c_0, g_0.first AS c_1, g_0.last AS c_2 FROM CustomerMaster.Customers AS g_0 WHERE g_0.first = 'Miles' ORDER BY c_0"); //$NON-NLS-1$
- expectedQueries.add("SELECT g_0.id AS c_0, g_0.amount AS c_1 FROM Europe.CustAccts AS g_0 WHERE g_0.id = 100 ORDER BY c_0"); //$NON-NLS-1$
+ expectedQueries.add("SELECT DISTINCT g_0.id AS c_0, g_0.first AS c_1, g_0.last AS c_2 FROM CustomerMaster.Customers AS g_0 WHERE g_0.first = 'Miles' ORDER BY c_0"); //$NON-NLS-1$
+ expectedQueries.add("SELECT DISTINCT g_0.id AS c_0, g_0.amount AS c_1 FROM Europe.CustAccts AS g_0 WHERE g_0.id = 100 ORDER BY c_0"); //$NON-NLS-1$
}
assertEquals(expectedQueries, dataManager.getQueries());
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java 2009-07-31 13:15:35 UTC (rev 1210)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestSortNode.java 2009-07-31 15:42:46 UTC (rev 1211)
@@ -32,7 +32,6 @@
import java.util.Set;
import org.junit.Test;
-import org.mockito.Mockito;
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixProcessingException;
@@ -43,7 +42,6 @@
import com.metamatrix.common.buffer.TupleBatch;
import com.metamatrix.common.buffer.TupleSource;
import com.metamatrix.common.buffer.TupleSourceID;
-import com.metamatrix.common.buffer.BufferManager.TupleSourceStatus;
import com.metamatrix.common.buffer.BufferManager.TupleSourceType;
import com.metamatrix.common.buffer.impl.SizeUtility;
import com.metamatrix.common.types.DataTypeManager;
15 years, 4 months
teiid SVN: r1210 - in trunk/console/src: main/java/org/teiid/rhq/admin and 15 other directories.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-07-31 09:15:35 -0400 (Fri, 31 Jul 2009)
New Revision: 1210
Added:
trunk/console/src/assembly/assemble-artifacts.xml
trunk/console/src/assembly/binaries.xml
trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java
trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java
trunk/console/src/main/java/org/teiid/rhq/comm/Component.java
trunk/console/src/main/java/org/teiid/rhq/comm/Connection.java
trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionConstants.java
trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionException.java
trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionFactory.java
trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPool.java
trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPoolConstants.java
trunk/console/src/main/java/org/teiid/rhq/comm/ExecutedResult.java
trunk/console/src/main/java/org/teiid/rhq/comm/VMComponent.java
trunk/console/src/main/java/org/teiid/rhq/comm/impl/ComponentImpl.java
trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionImpl.java
trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionUtil.java
trunk/console/src/main/java/org/teiid/rhq/comm/impl/InvalidConnectionImpl.java
trunk/console/src/main/java/org/teiid/rhq/comm/impl/NetUtils.java
trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionConstants.java
trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionFactory.java
trunk/console/src/main/java/org/teiid/rhq/embedded/EmbeddedConnectionMgr.java
trunk/console/src/main/java/org/teiid/rhq/embedded/pool/ConnectionPoolImpl.java
trunk/console/src/main/java/org/teiid/rhq/embedded/pool/EmbeddedConnectionConstants.java
trunk/console/src/main/java/org/teiid/rhq/enterprise/AdminUtil.java
trunk/console/src/main/java/org/teiid/rhq/enterprise/EnterpriseConnectionMgr.java
trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/ConnectionPoolImpl.java
trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/EnterpriseConnectionConstants.java
trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java
trunk/console/src/main/java/org/teiid/rhq/plugin/HostComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/HostDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/SecurityComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/SystemComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/log/JBEDSPErrorLogEntryProcessor.java
trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ConfigurationResultImpl.java
trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedOperationResultImpl.java
trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedResourceConfigurationResultImpl.java
trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginUtils.java
trunk/console/src/main/java/org/teiid/rhq/plugin/util/configuration.properties
trunk/console/src/resources/embedded/META-INF/rhq-plugin.xml
trunk/console/src/resources/enterprise/META-INF/rhq-plugin.xml
trunk/console/src/test/java/org/teiid/rhq/AllTests.java
trunk/console/src/test/java/org/teiid/rhq/StartingEnvironmentConstants.java
trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java
trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java
trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java
trunk/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java
Log:
moving jbedsp-monitor project into teiid as the starting point for teiid-console
Added: trunk/console/src/assembly/assemble-artifacts.xml
===================================================================
--- trunk/console/src/assembly/assemble-artifacts.xml (rev 0)
+++ trunk/console/src/assembly/assemble-artifacts.xml 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,71 @@
+<project default="main" name="JON.Plugin.Build" basedir="../../">
+
+ <property name="temp.dir" value="${basedir}/target/tmp"/>
+ <property name="embedded.temp.dir" value="${temp.dir}/embedded"/>
+
+ <!-- this contains jars to be included in the embedded war -->
+ <property name="embedded.jar" value="${basedir}/target/distribution/jbedsp-embedded-plugin-${product.version}.jar"/>
+
+ <property name="enterprise.temp.dir" value="${temp.dir}/enterprise"/>
+ <!-- this is the plugin to be deployed to JON that get sent to the agent -->
+ <property name="enterprise.jar" value="${basedir}/target/distribution/jbedsp-enterprise-plugin-${product.version}.jar"/>
+
+
+ <property name="bin.dir" value="${basedir}/target/distribution/${product.name}-${product.version}-binaries.jar"/>
+
+ <target name="main" depends="build-embedded-jar, build-enterprise-jar" />
+
+ <target name="build-embedded-jar" >
+ <!-- assemble the jars into the embeddedjars dir, to be zipped up -->
+
+ <!-- assemble the plugin jar -->
+ <mkdir dir="${embedded.temp.dir}"/>
+ <copy todir="${embedded.temp.dir}">
+ <fileset dir="${basedir}/src/resources/embedded"/>
+ </copy>
+
+ <unzip src="${basedir}/target/${product.name}-${product.version}.jar" dest="${embedded.temp.dir}">
+ <patternset>
+ <exclude name="com/metamatrix/rhq/enterprise/**"/>
+ </patternset>
+ </unzip>
+ <!--
+ <unjar dest="${embedded.temp.dir}/">
+ <fileset file="${basedir}/target/${product.name}-${product.version}.jar" />
+ <patternset>
+ <exclude name="com/metamatrix/rhq/enterprise/**"/>
+ </patternset>
+ </unjar>
+
+ -->
+ <!-- jar up the plugin file -->
+ <jar destfile="${embedded.jar}" basedir="${embedded.temp.dir}"/>
+
+ <!--
+ <delete dir="${embedded.temp.dir}"/>
+-->
+
+ </target>
+
+ <target name="build-enterprise-jar" >
+ <mkdir dir="${enterprise.temp.dir}"/>
+
+
+ <copy todir="${enterprise.temp.dir}">
+ <fileset dir="${basedir}/src/resources/enterprise"/>
+ </copy>
+
+ <unzip src="${basedir}/target/${product.name}-${product.version}.jar" dest="${enterprise.temp.dir}">
+ <patternset>
+ <exclude name="com/metamatrix/rhq/embedded/**"/>
+ </patternset>
+ </unzip>
+
+ <jar destfile="${enterprise.jar}" basedir="${enterprise.temp.dir}"/>
+<!--
+ <delete dir="${enterprise.temp.dir}"/>
+ -->
+ </target>
+
+
+</project>
\ No newline at end of file
Property changes on: trunk/console/src/assembly/assemble-artifacts.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/assembly/binaries.xml
===================================================================
--- trunk/console/src/assembly/binaries.xml (rev 0)
+++ trunk/console/src/assembly/binaries.xml 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,23 @@
+<!--This script builds a JAR for a Server Installation -->
+<assembly>
+
+ <id>binaries</id>
+
+ <formats>
+ <format>dir</format>
+ </formats>
+
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <baseDirectory>server</baseDirectory>
+
+ <dependencySets>
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <useTransitiveDependencies>true</useTransitiveDependencies>
+ <useTransitiveFiltering>false</useTransitiveFiltering>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ <unpack>false</unpack>
+ </dependencySet>
+ </dependencySets>
+
+</assembly>
\ No newline at end of file
Property changes on: trunk/console/src/assembly/binaries.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,66 @@
+package org.teiid.rhq.admin;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+
+
+public interface ConnectionMgr {
+
+ /**
+ * Called to indicate that this manager should be initialized.
+ * @param props
+ * @param cl is the ClassLoader to use to instantiate any classes downstream
+ */
+ void initialize(Properties props, ClassLoader cl);
+
+ /**
+ * Called to reset the pool. A subsequent call to @see #initialize(Properties, ClassLoader)
+ * would establish a new set of installations based on the properties.
+ */
+ void shutdown();
+
+ /**
+ * Returns <code>true</code> if server installations have been configured and will be returned
+ * in the {@link #getServerInstallations()} call.
+ * @return true if servers are defined.
+ */
+
+ boolean hasServersDefined();
+
+
+ /**
+ * Returns the unique set of keys for each installation
+ * @return Set of unique keys
+ */
+ Set getInstallationSystemKeys();
+
+
+
+ /**
+ * this is called only during discovery to obtain a connection for each
+ * system (or server installation) on the local machine.
+ *
+ * In cases where a connection cannot be obtained, an entry in the
+ * <code>Map</code> will be added with a null set for the value <code>Connection</code>
+ * @return Map <key=installdir value=Connection>
+ * @throws Exception
+ * @since 1.0
+ */
+ Map<String, Connection> getServerInstallations();
+
+ /**
+ * Called to get a {@link Connection} that will be used to
+ * call the MetaMatrix Server.
+ * @param key is the unique identifier for the system in
+ * which to obtain the connection for.
+ * @return Connection for the system to communicate with.
+ * @throws Exception
+ * @since 1.0
+ */
+ Connection getConnection(String key) throws ConnectionException;
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/admin/ConnectionMgr.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.admin.utils;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.teiid.rhq.admin.ConnectionMgr;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+
+
+public class SingletonConnectionManager {
+
+ private static final Log log = LogFactory.getLog(SingletonConnectionManager.class);
+
+ private static final String ENTERPRISE_CONNECTION_MGR="org.teiid.rhq.enterprise.EnterpriseConnectionMgr"; //$NON-NLS-1$
+ private static final String EMBEDDED_CONNECTION_MGR="org.teiid.rhq.embedded.EmbeddedConnectionMgr"; //$NON-NLS-1$
+
+ private static SingletonConnectionManager instance = null;
+ private ConnectionMgr connmgr;
+ private ClassLoader loader;
+ private boolean initialized = false;
+
+
+ private SingletonConnectionManager() {
+
+
+ }
+
+ public synchronized static SingletonConnectionManager getInstance() {
+
+ if (instance == null) {
+ instance = new SingletonConnectionManager();
+ instance.setupConnectionMgr();
+ }
+
+ return instance;
+ }
+
+ public Set getInstallationSystemKeys() {
+ return connmgr.getInstallationSystemKeys();
+ }
+
+ public Connection getConnection(String key) throws ConnectionException {
+ return connmgr.getConnection(key);
+ }
+
+
+ public void initialize(Properties props) {
+ if (connmgr != null && initialized) {
+ // re-establish the connectionfactory and pool
+ shutdown();
+ setupConnectionMgr();
+ }
+ initializeConnectionMgr(props);
+
+ }
+
+ public Map getServerInstallations() {
+ return connmgr.getServerInstallations();
+ }
+
+ public boolean hasServersDefined() {
+ return connmgr.hasServersDefined();
+ }
+
+ public void shutdown() {
+ connmgr.shutdown();
+ connmgr = null;
+ }
+
+
+
+ private void setupConnectionMgr() {
+ this.loader = this.getClass().getClassLoader();
+ ConnectionMgr mgr = null;
+ Class clzz = null;
+ // first try enterprise version
+ try {
+ clzz = Class.forName(ENTERPRISE_CONNECTION_MGR, true, this.loader);
+ } catch (ClassNotFoundException noent) {
+
+ // no try the embedded connection pool version
+ try {
+ clzz = Class.forName(EMBEDDED_CONNECTION_MGR, true, this.loader);
+ } catch (ClassNotFoundException noemb) {
+
+ }
+ }
+
+ if (clzz == null) {
+ throw new InvalidPluginConfigurationException("System Error: cannot load either enterprise or embedded connection mgr");
+ }
+
+ try {
+ mgr = (ConnectionMgr) clzz.newInstance();
+ } catch (Exception e) {
+ throw new InvalidPluginConfigurationException(e);
+ }
+
+ this.connmgr = mgr;
+
+ }
+
+ private void initializeConnectionMgr(Properties props) {
+
+ connmgr.initialize(props, this.loader);
+ this.initialized = true;
+
+ }
+
+ public boolean isEmbedded() {
+ try {
+ Class.forName(EMBEDDED_CONNECTION_MGR);
+ return true;
+ } catch (ClassNotFoundException noent) {
+ return false;
+ }
+ }
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/admin/utils/SingletonConnectionManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/Component.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/Component.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/Component.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+import java.util.Map;
+
+
+/**
+ * @since 4.3
+ */
+public interface Component extends Comparable<Object> {
+
+ public static final String SYSTEM_KEY = "teiid.system.key"; //$NON-NLS-1$
+ public static final String NAME = "teiid.name"; //$NON-NLS-1$
+ public static final String IDENTIFIER = "teiid.identifier"; //$NON-NLS-1$
+ public static final String DESCRIPTION = "teiid.description"; //$NON-NLS-1$
+ public static final String VERSION = "teiid.version"; //$NON-NLS-1$
+
+ /**
+ * Return the system key that this component identifies with.
+ * @return String system key
+ */
+ String getSystemKey();
+
+ /**
+ * Return the name for this component
+ * @return String name
+ */
+ String getName();
+
+ /**
+ * return the unique identifier for this component
+ * @return String unique identifier
+ */
+ String getIdentifier();
+
+ /**
+ * Return the description
+ * @return String description
+ */
+ String getDescription();
+
+ /**
+ * Return the version
+ * @return String version
+ */
+ String getVersion();
+
+ /**
+ * Return a value for the request property key
+ * @param key is the identifier to look for
+ * @return String value
+ */
+ String getProperty(String key);
+
+
+ /**
+ * Return the map of properties.
+ * @return Map of properties
+ */
+ Map getProperties();
+
+
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/Component.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/Connection.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/Connection.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/Connection.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.rhq.admin.utils.SingletonConnectionManager;
+
+
+
+public interface Connection {
+
+ /**
+ * Called to find out if the connection represents a valid connection to the
+ * JBEDSP system. This call should be used only after obtaining a connection
+ * from the {@link SingletonConnectionManager#getConnection(String)}.
+ * The connection can become invalid if the JBEDSP system goes down.
+ */
+ boolean isValid();
+
+ /**
+ * Called by the {@link ConnectionPool} to check if the connection is still open.
+ * @return true is the connection is alive.
+
+ */
+ boolean isAlive();
+
+ /**
+ * Call to indicate the connection is no longer needed and that
+ * resources can be released.
+ */
+ public void close() ;
+
+
+ /**
+ * This method is called by a component of the JBEDSP RHQ plugin. The
+ * component identifier, type and metric operation are used to execute the correlating logic.
+ * The valueMap is a map of values (0-n) that are required by
+ * the logic to determine the metric.
+ * @param componentType @see ConnectionConstants.ComponentType
+ * @param identifier
+ * @param metric
+ * @param valueMap
+ * @return Object
+ * @throws ConnectionException
+ */
+ public Object getMetric(final String componentType, String identifier, final String metric, final Map valueMap) throws ConnectionException;
+
+ /**
+ * This method is called by a component of the JBEDSP RHQ plugin. The
+ * component type and operation are used to execute the correlating logic.
+ * The valueMap is a collection of values (0-n) that are required by
+ * the operation.
+ * {@link ConnectionConstants.ComponentType} for <code>componentType</code> values
+ * @param result
+ * @param componentType
+ * @param operationName
+ * @param valueMap
+ * @throws ConnectionException
+ */
+ public void executeOperation(final ExecutedResult result, final Map valueMap) throws ConnectionException;
+
+ /**
+ * This method is called by a component to determine if that particular component is con. The
+ * component type and identifier are used to execute the correlating logic.
+ *
+ * {@link ConnectionConstants.ComponentType} for <code>componentType</code> values
+ *
+ * The return value is true if UP else false if DOWN
+ *
+ * @param componentType
+ * @param identifier
+ * @return Boolean
+ * @throws ConnectionException
+ */
+ public Boolean isAvailable(final String componentType, final String identifier) throws ConnectionException;
+
+
+ /**
+ * Return the properties for component of a specified resource type {@link ConnectionConstants.ComponentType}
+ * @param componentType {@link ConnectionConstants.ComponentType}
+ * @param identifier
+ * @return
+ * @throws ConnectionException
+ * @since 4.3
+ */
+
+ public Properties getProperties(String componenType, String identifier) throws ConnectionException;
+
+ /**
+ * Returns a property for a given identifier
+ *
+ * @param identifier
+ * @param property
+ * @throws ConnectionException
+ */
+ public String getProperty(String identifier, String property) throws ConnectionException;
+
+ /**
+ * Returns the unique key that maps this connection to the system that is being connected to.
+ * This key used during the enterprise monitoring to keep track of which connection belongs to
+ * what's being monitored.
+ *
+ * @return key JBEDSP represented by this connection
+ * @throws Exception
+ */
+ public String getKey() throws Exception;
+
+ /**
+ * Returns a <code>Collection</code> of {@link Component Component}s for the given identifier for the
+ * given name of the {@link ConnectionConstants.ComponentType}
+ * @param componentType
+ * @param identifier
+ * @return
+ * @throws ConnectionException
+ */
+ public Collection<Component> discoverComponents(String componentType, String identifier) throws ConnectionException;
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/Connection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionConstants.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionConstants.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionConstants.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,235 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+
+/**
+ * These are the Constants that used in conjunction with using the
+ * @since 5.5.3
+ */
+public interface ConnectionConstants {
+
+
+ public static final String VERSION = "6.0.0";
+
+ /**
+ * These are Environment properties need to create a connection. They will be exposed via the @see #getEnvironment call.
+ */
+
+ // The system key is the value used to obtain a connection.
+ // In embedded, its a predefined value
+ // In enterprise, its the installation directory
+ public final static String SYSTEM_KEY = "system.key"; //$NON-NLS-1$
+ public final static String USERNAME = "username"; //$NON-NLS-1$
+ public final static String PASSWORD = "password"; //$NON-NLS-1$
+ public final static String URL = "url"; //$NON-NLS-1$
+// public final static String INSTALL_DIR = "install.dir"; //$NON-NLS-1$
+
+ /**
+ * These are global properties used by all components
+ */
+ /*
+ * This is the key for the fully qualified identifier.
+ * For Runtime components it should be the deployedcomponent full name
+ * For Resource components it should be the Service Defn full name
+ * for adding to the value maps for metrics and operations.
+ */
+ public final static String IDENTIFIER = "identifier"; //$NON-NLS-1$
+
+
+ /**
+ * These properties are exposed via the #getProperty method call.
+ */
+ public static String SYSTEM_NAME = "cluster.name"; //$NON-NLS-1$
+ public static String SYSTEM_NAME_IDENTIFIER = "JGroups"; //$NON-NLS-1$
+
+ /**
+ * Use these component type names when calling Connection related methods
+ * that require the type.
+ * @since 1.0
+ */
+ public interface ComponentType {
+ public final static String PLATFORM = "Platform"; //$NON-NLS-1$
+
+ public interface Runtime {
+
+ public interface System {
+ public final static String TYPE = "Runtime.System"; //$NON-NLS-1$
+
+ public static interface Operations {
+
+ public final static String BOUNCE_SYSTEM = "bounceSystem"; //$NON-NLS-1$
+ public final static String GET_LONGRUNNINGQUERIES = "listLongRunningQueries"; //$NON-NLS-1$
+
+ }
+
+ public static interface Metrics {
+
+ public final static String QUERY_COUNT = "queryCount"; //$NON-NLS-1$
+ public final static String SESSION_COUNT = "sessionCount"; //$NON-NLS-1$
+ public final static String LONG_RUNNING_QUERIES = "longRunningQueries"; //$NON-NLS-1$
+
+ }
+ }
+
+ public interface Host {
+ public final static String TYPE = "Runtime.Host"; //$NON-NLS-1$
+
+ public static interface Operations {
+ public final static String GET_HOSTS = "getHosts"; //$NON-NLS-1$
+
+ }
+ }
+
+ public interface Process {
+
+ public final static String TYPE = "Runtime.Process"; //$NON-NLS-1$
+ public static interface Operations {
+
+ }
+
+ }
+
+
+ public interface Connector {
+
+ public final static String TYPE = "Runtime.Connector"; //$NON-NLS-1$
+ public static interface Operations {
+
+ public final static String RESTART_CONNECTOR = "restart"; //$NON-NLS-1$
+ public final static String STOP_CONNECTOR = "stop"; //$NON-NLS-1$
+
+ }
+
+ }
+
+// public interface Service {
+//
+// public final static String TYPE = "Runtime.Service"; //$NON-NLS-1$
+// public static interface Operations {
+//
+// public final static String RESTART_SERVICE = "restart"; //$NON-NLS-1$
+// public final static String STOP_SERVICE = "stop"; //$NON-NLS-1$
+//
+// }
+//
+// }
+
+ public interface Session {
+
+ public final static String TYPE = "Runtime.Sesssion"; //$NON-NLS-1$
+ public static interface Query {
+
+ public final static String GET_SESSIONS = "getSessions"; //$NON-NLS-1$
+ }
+
+
+
+ }
+
+ public interface Queries {
+
+ public final static String TYPE = "Runtime.Queries"; //$NON-NLS-1$
+ public static interface Query {
+
+ public final static String GET_QUERIES = "listQueries"; //$NON-NLS-1$
+ }
+
+
+
+ }
+
+ }
+ public interface Resource {
+ public interface Service {
+
+ public final static String TYPE = "Resource.Service"; //$NON-NLS-1$
+ public static interface Operations {
+
+ }
+
+ public static interface Query {
+
+ }
+
+ }
+ public interface Connector {
+
+ public final static String TYPE = "Resource.Connector"; //$NON-NLS-1$
+ public static interface Operations {
+
+ }
+
+ }
+ }
+
+ public interface Security {
+
+ }
+ /**
+ * Use these metric names when calling getValues() on the connection
+ * interface.
+ * @since 1.0
+ */
+ public interface Metric {
+ public final static String HIGH_WATER_MARK = "highWatermark"; //$NON-NLS-1$
+
+ }
+
+ /**
+ * Use these operation names when calling executeOperation() on the connection
+ * interface.
+ * @since 1.0
+ */
+ public static interface Operation {
+ public final static String KILL_REQUEST = "killRequest"; //$NON-NLS-1$
+ public final static String GET_VDBS = "listVDBs"; //$NON-NLS-1$
+
+ public final static String GET_PROPERTIES = "getProperties"; //$NON-NLS-1$
+
+ /**
+ * Use these value names when calling executeOperation() on the connection
+ * interface. These will correlate with parameters used in operations.
+ * @since 1.0
+ */
+ public static interface Value {
+ public final static String STOP_NOW = "stopNow"; //$NON-NLS-1$
+ public final static String WAIT_UNTIL_FINISHED = "waitUntilFinished"; //$NON-NLS-1$
+
+ public final static String INCLUDE_SOURCE_QUERIES = "includeSourceQueries"; //$NON-NLS-1$
+
+ public final static String LONG_RUNNING_QUERY_LIMIT = "longRunningQueryLimit"; //$NON-NLS-1$
+
+ public final static String FIELD_LIST = "fieldList"; //$NON-NLS-1$
+
+ public final static String REQUEST_ID = "requestID"; //$NON-NLS-1$
+
+ public final static String NAME = "Name"; //$NON-NLS-1$
+ public final static String VALUE = "Value"; //$NON-NLS-1$
+
+ }
+
+ }
+
+ }
+
+ }
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionException.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionException.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionException.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+
+/**
+ * @since 4.3
+ */
+public class ConnectionException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3342409142882071873L;
+
+
+ public ConnectionException() {
+ super();
+ }
+
+
+ public ConnectionException(final String msg) {
+ super(msg);
+ }
+
+
+ public ConnectionException(final Exception e) {
+ super(e);
+ }
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionFactory.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionFactory.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionFactory.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+import java.util.Properties;
+
+
+/**
+ * The primary interface to be implemented by the pool user. The ConnectionFactory
+ * is called by the {@link ConnectionPool} to create and close the connection.
+ *
+ *
+ * This
+ */
+public interface ConnectionFactory {
+
+ public static final String CONNECTION_FACTORY_DEFAULT="org.teiid.rhq.comm.impl.TeiidConnectionFactory"; //$NON-NLS-1$
+
+
+
+ /**
+ * Set the environment that this factory is being run in - typically used
+ * to obtain properties when creating connections and to log messages as
+ * necessary.
+ * @param env The environment properties needed to create a connection by the connector manager
+ * {@link ConnectionConstants}
+ * @param connectionPool is passed so the factory can set the pool on the connection.
+ */
+ void initialize(Properties env, ConnectionPool connectionPool) throws ConnectionException;
+
+ /**
+ * Return the url used to connect to the server.
+ * @return String url
+ */
+ String getURL();
+
+ /**
+ * Create the connection. This connection is to an existing MetaMatrix server.
+ * @return The Connection form of source-specific connection
+ * @throws ConnectorException If an error occurs while creating the connection
+ */
+ Connection createConnection() throws ConnectionException;
+
+
+ /**
+ * Called by the {@link ConnectionPool} when a connection is being cleaned up from the pool.
+ * This will allow the creator of the connection to do any last cleanup steps necessary in order
+ * to release all resources.
+ *
+ * In cases where the {@link Connection}, when the {@link Connection#close()} method only returns
+ * the connection to the pool and does not actually close the connection, this close will be
+ * responsible for actually closing the connection to the source.
+ * @param connection
+
+ */
+ void closeConnection(Connection connection) ;
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPool.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPool.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPool.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+import java.util.Properties;
+
+
+
+
+/**
+ * The primary interface for the ConnectionPool used by the connection manager
+ * responsible for handing out connections to the discovery and resource JON objects.
+ *
+ * After the instantiation of the ConnectionPool, the @link #initialize(String, Properties) method
+ * will be called so the pool can be initialized.
+ * @since 1.0
+ *
+ */
+public interface ConnectionPool extends ConnectionPoolConstants {
+
+
+ /**
+ * Set the connection factory responsible for creating a connection
+ * when the pool needs a new one. @see ConnectionPoolConstants for the
+ * avalable settings to configure the pool.
+ * @param env are the environment variables needed to iniatilize the connection pool.
+ * @since 1.0
+ */
+ void initialize(Properties env, ClassLoader cl) throws ConnectionException ;
+
+ /**
+ * Return a unique key that identifies this connection pool
+ *
+ * @return
+ */
+ String getKey();
+
+
+ /**
+ * Returns a {@link Connection} from the pool.
+ * @return Connction
+ */
+ Connection getConnection() throws ConnectionException;
+
+
+ /**
+ * Return the connection to the pool. It's up to the
+ * implementation of the pool if the connection is reused or not
+ * @param connection returned to the pool
+ */
+ void close(Connection connection) throws ConnectionException;
+
+
+ /**
+ * Called to shutdown the pool.
+ *
+ */
+ void shutdown() throws ConnectionException;
+
+
+ /**
+ * Return the <code>ClassLoader</code> used to instantiate the {@link ConnectionFactory} and
+ * will be used on all calls in the {@link Connection}
+ * @return
+ */
+ ClassLoader getClassLoader();
+
+ /**
+ * Return the number of connection that are currently in use.
+ * @return int is the number of connections in use
+ *
+ * @since
+ */
+ int getConnectionsInUseCount();
+
+ /**
+ * Return the number of connections that are currently available in the pool.
+ * @return int is the number of connections currently available in the pool.
+ *
+ * @since 6.2
+ */
+ int getAvailableConnectionCount();
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPool.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPoolConstants.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPoolConstants.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPoolConstants.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+
+
+/**
+ * These are the properties are used by the {@link ConnectionPool) to create and manage
+ * connections. These properties are passed into the pool when at initialization time.
+ * @since 1.0
+ */
+public interface ConnectionPoolConstants {
+
+ /**
+ * Indicates the connection factory to use in the connection pool.
+ */
+ public static final String CONNECTION_FACTORY = "pool.connection.factory"; //$NON-NLS-1$
+
+ /**
+ * Maximum connections for this pool. Default to 0, which means there is no limit.
+ */
+// public static final String MAX_CONNECTIONS = "pool.max_connections"; //$NON-NLS-1$
+
+ /**
+ * Idle time of the connection before it should be closed in seconds. Default to 60 seconds.
+ */
+ public static final String LIVE_AND_UNUSED_TIME = "pool.live_and_unused_time"; //$NON-NLS-1$
+
+ /**
+ * Time to wait if the connection is not available in milliseconds. Default to 2 seconds.
+ */
+ public static final String WAIT_FOR_SOURCE_TIME = "pool.wait_for_source_time"; //$NON-NLS-1$
+
+ /**
+ * Interval for running the cleaning thread in seconds. Default to 60 seconds.
+ */
+ public static final String CLEANING_INTERVAL = "pool.cleaning_interval"; //$NON-NLS-1$
+
+ /**
+ * Whether to enable pool shrinking. Default to true.
+ */
+ public static final String ENABLE_SHRINKING = "pool.enable_shrinking"; //$NON-NLS-1$
+
+ /**
+ * This property is used to specify the length of time between JDBC Source test connections
+ * How often (in seconds) to test that the data source is available by establishing a new connection. Default to 600 seconds.
+ */
+// public static final String CONNECTION_TEST_INTERVAL = "pool.connection.test.interval"; //$NON-NLS-1$
+
+
+
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/ConnectionPoolConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/ExecutedResult.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/ExecutedResult.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/ExecutedResult.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+import java.util.List;
+
+public interface ExecutedResult {
+
+ String getComponentType() ;
+
+ String getOperationName();
+
+ Object getResult();
+
+ List<String> getFieldNameList();
+
+ void setContent(List content);
+
+ void setContent(String content);
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/ExecutedResult.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/VMComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/VMComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/VMComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm;
+
+
+/**
+ * @since 4.3
+ */
+public interface VMComponent extends Component {
+ public static final String PORT = "mm.port"; //$NON-NLS-1$
+
+ String getPort();
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/VMComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/impl/ComponentImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/impl/ComponentImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/impl/ComponentImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,244 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm.impl;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.VMComponent;
+
+import com.metamatrix.core.util.HashCodeUtil;
+
+
+/**
+ */
+public class ComponentImpl implements VMComponent {
+ private String systemKey;
+ private String description;
+ private String name;
+ private String identifier;
+ private String version="1.0"; //$NON-NLS-1$
+ private String port;
+ int hashCode;
+
+
+ private Properties compprops = new Properties();
+
+
+ public void addProperty(String key, String value) {
+ compprops.put(key, value);
+ }
+
+ public void setProperties(Properties props) {
+ compprops.putAll(props);
+ }
+
+ public String getProperty(String key) {
+ return (String)compprops.get(key);
+ }
+
+ public Map getProperties() {
+ return compprops;
+ }
+
+ /**
+ * @return Returns the systemKey.
+ * @since 1.0
+ */
+ public String getSystemKey() {
+ return this.systemKey;
+ }
+
+
+ /**
+ * @param systemKey The systemKey to set.
+ * @since 1.0
+ */
+ public void setSystemKey(String systemKey) {
+ this.systemKey = systemKey;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Component#getDescription()
+ * @since 1.0
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Component#getIdentifier()
+ * @since 1.0
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Component#getName()
+ * @since 1.0
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Component#getVersion()
+ * @since 1.0
+ */
+ public String getVersion() {
+ return version;
+ }
+
+
+ /**
+ * @return Returns the port.
+ */
+ public String getPort() {
+ return this.port;
+ }
+
+
+
+ /**
+ * @param port The port to set.
+ */
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+
+ /**
+ * @param description The description to set.
+ * @since 1.0
+ */
+ protected void setDescription(String description) {
+ this.description = description;
+ }
+
+
+ /**
+ * @param identifier The identifier to set.
+ * @since 1.0
+ */
+ protected void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ this.hashCode = HashCodeUtil.hashCode(0, this.identifier);
+ }
+
+
+ /**
+ * @param name The name to set.
+ * @since 1.0
+ */
+ protected void setName(String name) {
+ this.name = name;
+ }
+
+
+ /**
+ * @param version The version to set.
+ * @since 1.0
+ */
+ protected void setVersion(String version) {
+ this.version = version;
+ }
+
+ /**
+ * Returns true if the specified object is semantically equal to this instance.
+ * Note: this method is consistent with <code>compareTo()</code>.
+ * <p>
+ * @param obj the object that this instance is to be compared to.
+ * @return whether the object is equal to this object.
+ */
+ public boolean equals(Object obj) {
+ // Check if instances are identical ...
+ if (this == obj) {
+ return true;
+ }
+
+ // Check if object can be compared to this one
+ // (this includes checking for null ) ...
+ if (obj instanceof Component) {
+
+
+ // fail fast on different hash codes
+ if (this.hashCode() != obj.hashCode()) {
+ return false;
+ }
+
+ // slower comparison
+ Component that = (Component)obj;
+ return ( that.getSystemKey().equals(this.getSystemKey()) );
+ }
+
+ // Otherwise not comparable ...
+ return false;
+ }
+
+ /**
+ * Compares this object to another. If the specified object is an instance of
+ * the same class, then this method compares the name; otherwise, it throws a
+ * ClassCastException (as instances are comparable only to instances of the same
+ * class). Note: this method is consistent with <code>equals()</code>.
+ * <p>
+ * @param obj the object that this instance is to be compared to.
+ * @return a negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object, respectively.
+ * @throws ClassCastException if the specified object's type prevents it
+ * from being compared to this instance.
+ */
+ public int compareTo(Object obj) {
+ // Check if instances are identical ...
+ if (this == obj) {
+ return 0;
+ }
+ if (obj == null ) {
+ throw new IllegalArgumentException("Object is null, must be of type " + this.getClass().getName());
+ }
+
+ // Check if object cannot be compared to this one
+ // (this includes checking for null ) ...
+ if (!(obj instanceof Component)) {
+ throw new IllegalArgumentException(obj.getClass().getName() + " is not of type " + this.getClass().getName());
+ }
+
+ // Check if everything else is equal ...
+ Component that = (Component)obj;
+ int result = that.hashCode() - this.hashCode;
+ if ( result != 0 ) return result;
+ return this.getIdentifier().compareTo(that.getIdentifier());
+ }
+
+ /**
+ * Returns a string representing this instance.
+ * @return the string representation of this instance.
+ */
+ public String toString() {
+ return this.getIdentifier();
+ }
+
+
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/impl/ComponentImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,1340 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm.impl;
+
+import java.lang.reflect.Method;
+import java.net.UnknownHostException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.teiid.adminapi.Admin;
+import org.teiid.adminapi.AdminException;
+import org.teiid.adminapi.AdminObject;
+import org.teiid.adminapi.ConnectorBinding;
+import org.teiid.adminapi.Host;
+import org.teiid.adminapi.ProcessObject;
+import org.teiid.adminapi.QueueWorkerPool;
+import org.teiid.adminapi.Request;
+import org.teiid.adminapi.Session;
+import org.teiid.adminapi.SystemObject;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionPool;
+import org.teiid.rhq.comm.ExecutedResult;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries.Query;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.System.Metrics;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.System.Operations;
+import org.teiid.rhq.plugin.HostComponent;
+
+import com.metamatrix.jdbc.MMConnection;
+import com.metamatrix.platform.security.api.MetaMatrixSessionState;
+
+public class ConnectionImpl implements Connection, TeiidConnectionConstants {
+
+ // TODO:
+ // 1. Change from using LogManager. This writes to the MM Server, the
+ // messages should be
+ // written to the agent log
+ // 2. Need to support connecting via ssl
+ // 3. Need to understand the life cycle of a connection
+ // a. during discovery
+ // b. during monitoring, operations, etc.
+ // 4. add post processing for calculated fields in operation results
+
+
+ private static final Log log = LogFactory.getLog(ConnectionImpl.class);
+
+ public String key = "";
+
+ private Properties environmentProps = null;
+
+ private Admin adminApi = null;
+ private MMConnection mmconn = null;
+
+ private ConnectionPool connectionPool = null;
+
+ // set when an exception is thrown by the admin api
+ // and indicates when close is called, to tell the pool
+ // to remove the connection;
+ private boolean invalidConnection = false;
+
+ protected ConnectionImpl (final String key,
+ final Properties envProps,
+ final ConnectionPool pool,
+ final MMConnection connection) throws SQLException {
+ this.connectionPool = pool;
+ this.mmconn = connection;
+ this.adminApi = this.mmconn.getAdminAPI();
+ this.key = key;
+ this.environmentProps = envProps;
+
+ }
+
+ public boolean isValid() {
+ return (! this.invalidConnection);
+ }
+ /**
+ * @see org.teiid.rhq.comm.Connection#isAlive()
+ */
+ public boolean isAlive() {
+ try {
+ if (adminApi != null) {
+ adminApi.getSystem();
+ this.invalidConnection=false;
+ return true;
+ }
+ } catch (Throwable e) {
+ invalidConnection = true;
+ log.error("Error: admin connection for " + key + " is not alive", e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return false;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#close()
+ */
+ public void close() {
+ try {
+ if (connectionPool != null) {
+ connectionPool.close(this);
+ }
+
+ } catch (Exception e) {
+ log.error("Error returning connection to the connection pool", e); //$NON-NLS-1$
+ }
+
+ invalidConnection = true;
+
+ }
+
+
+ /**
+ * Called by the factory to close the source connection
+ *
+ */
+
+ protected void closeSource() {
+ try {
+ if (mmconn != null) {
+ mmconn.close();
+ }
+ } catch (Exception e) {
+ log.error("Error closing the admin connection", e); //$NON-NLS-1$
+ } finally {
+ adminApi = null;
+ mmconn = null;
+ connectionPool = null;
+ environmentProps.clear();
+ environmentProps = null;
+ this.invalidConnection = true;
+
+ }
+ }
+
+// public Properties getEnvironment() throws ConnectionException {
+// Properties systemProperties = new Properties();
+// try {
+// Collection processCollection = ConnectionUtil.getAllProcesses(
+// getConnection(), this.getHost().getIdentifier());
+//
+// Iterator processIter = processCollection.iterator();
+// String portList = null;
+//
+// boolean first = true;
+// while (processIter.hasNext()) {
+// ProcessObject process = (ProcessObject) processIter.next();
+// if (first) {
+// first = false;
+// portList = String.valueOf(process.getPort());
+// } else {
+// portList += PORT_DELIM + process.getPort(); //$NON-NLS-1$
+// }
+//
+// }
+//
+// systemProperties.setProperty(ConnectionConstants.USERNAME,
+// environmentProps.getProperty(ConnectionConstants.USERNAME));
+// systemProperties.setProperty(ConnectionConstants.PASSWORD,
+// environmentProps.getProperty(ConnectionConstants.PASSWORD));
+// systemProperties.setProperty(ConnectionConstants.PORTS, portList);
+// environmentProps = (Properties) systemProperties.clone();
+//
+// return systemProperties;
+// } catch (AdminException ae) {
+// invalidConnection = true;
+// throw new ConnectionException(ae.getMessage());
+// } finally {
+// this.resetConnection();
+// }
+// }
+
+ public Collection<Component> discoverComponents(String componentType,
+ String identifier) throws ConnectionException {
+ if (componentType
+ .equals(Runtime.Connector.TYPE)) {
+ return getConnectors(identifier);
+
+// } else if (componentType
+// .equals(Runtime.Service.TYPE)) {
+// return getServices(identifier);
+
+ } else if (componentType
+ .equals(Runtime.Process.TYPE)) {
+ return getVMs(identifier);
+
+ } else if (componentType
+ .equals(Runtime.Host.TYPE)) {
+ return getAllHosts();
+
+// } else if (componentType
+// .equals(ComponentType.Resource.Service.TYPE)) {
+// return getServicesForConfig(identifier);
+//
+// } else if (componentType
+// .equals(ComponentType.Resource.Connector.TYPE)) {
+// return getConnectorsForConfig(identifier);
+
+ }
+// else if (componentType
+// .equals(ComponentType.Runtime.Session.TYPE)) {
+// return getConnectorsForConfig(identifier);
+//
+// }
+ return Collections.EMPTY_LIST;
+ }
+
+
+
+ public void executeOperation(ExecutedResult operationResult,
+ final Map valueMap) throws ConnectionException {
+
+ if (operationResult.getComponentType().equals(Runtime.Connector.TYPE)) {
+ executeConnectorOperation(operationResult, operationResult.getOperationName(), valueMap);
+ } else if (operationResult.getComponentType().equals(ConnectionConstants.ComponentType.Runtime.System.TYPE)) {
+ executeSystemOperation(operationResult, operationResult.getOperationName(), valueMap);
+ } else if (operationResult.getComponentType().equals( Runtime.Process.TYPE)) {
+ executeProcessOperation(operationResult, operationResult.getOperationName(), valueMap);
+ } else if (operationResult.getComponentType().equals(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Host.TYPE)) {
+ executeHostOperation(operationResult, operationResult.getOperationName(), valueMap);
+ } else if (operationResult.getComponentType().equals(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session.TYPE)) {
+ executeSessionOperation(operationResult, operationResult.getOperationName(), valueMap);
+ } else if (operationResult.getComponentType().equals(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries.TYPE)) {
+ executeQueriesOperation(operationResult, operationResult.getOperationName(), valueMap);
+ }
+ }
+
+
+
+ private void executeSystemOperation(ExecutedResult operationResult, final String operationName, final Map valueMap)
+ throws ConnectionException {
+ Object resultObject = new Object();
+
+ if (operationName.equals(Operations.BOUNCE_SYSTEM)) {
+ Boolean waitUntilFinished = (Boolean)valueMap.get(ConnectionConstants.ComponentType.Operation.Value.WAIT_UNTIL_FINISHED);
+ bounceSystem(waitUntilFinished);
+ }else if (operationName.equals(Operations.GET_LONGRUNNINGQUERIES)) {
+ Boolean includeSourceQueries = (Boolean)valueMap.get(ConnectionConstants.ComponentType.Operation.Value.INCLUDE_SOURCE_QUERIES);
+ Integer longRunningValue = (Integer)valueMap.get(ConnectionConstants.ComponentType.Operation.Value.LONG_RUNNING_QUERY_LIMIT);
+ List fieldNameList = operationResult.getFieldNameList();
+ resultObject = getLongRunningQueries(includeSourceQueries, longRunningValue, fieldNameList);
+ operationResult.setContent((List)resultObject);
+ }else if (operationName.equals(ComponentType.Operation.KILL_REQUEST)) {
+ String requestID = (String)valueMap.get(ConnectionConstants.ComponentType.Operation.Value.REQUEST_ID);
+ cancelRequest(requestID);
+ }else if (operationName.equals(ComponentType.Operation.GET_VDBS)) {
+ List fieldNameList = operationResult.getFieldNameList();
+ resultObject = getVDBs(fieldNameList);
+ operationResult.setContent((List)resultObject);
+ }else if (operationName.equals(ComponentType.Operation.GET_PROPERTIES)) {
+ String identifier = (String)valueMap.get(ConnectionConstants.IDENTIFIER);
+ Properties props = getProperties(ConnectionConstants.ComponentType.Runtime.System.TYPE, identifier);
+ resultObject = createReportResultList(props);
+ operationResult.setContent((List)resultObject);
+ }
+
+ }
+
+ private void executeProcessOperation(ExecutedResult operationResult, final String operationName, final Map valueMap)
+ throws ConnectionException {
+ Object resultObject = new Object();
+
+ if (operationName.equals(ComponentType.Operation.GET_PROPERTIES)) {
+ String identifier = (String)valueMap.get(ConnectionConstants.IDENTIFIER);
+ Properties props = getProperties(Runtime.Process.TYPE, identifier);
+ resultObject = createReportResultList(props);
+ operationResult.setContent((List)resultObject);
+ }
+ }
+
+ private void executeHostOperation(ExecutedResult operationResult, final String operationName, final Map valueMap)
+ throws ConnectionException {
+ Object resultObject = new Object();
+
+ if (operationName.equals(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Host.Operations.GET_HOSTS)) {
+ String identifier = (String)valueMap.get(ConnectionConstants.IDENTIFIER);
+ Properties props = getProperties(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Host.TYPE, identifier);
+ resultObject = createReportResultList(props);
+ operationResult.setContent((List)resultObject);
+ }
+ }
+
+ private void executeConnectorOperation(ExecutedResult operationResult, final String operationName, final Map valueMap)
+ throws ConnectionException {
+ Object resultObject = new Object();
+ String identifier = (String)valueMap.get(ConnectionConstants.IDENTIFIER);
+
+ if (operationName.equals(Runtime.Connector.Operations.RESTART_CONNECTOR)) {
+ startConnector(identifier);
+ }else if (operationName.equals(Runtime.Connector.Operations.STOP_CONNECTOR)) {
+ Boolean stopNow = (Boolean)valueMap.get(ConnectionConstants.ComponentType.Operation.Value.STOP_NOW);
+ stopConnector(identifier, stopNow);
+ }else if (operationName.equals(ComponentType.Operation.GET_PROPERTIES)) {
+ Properties props = getProperties(Runtime.Connector.TYPE, identifier);
+ resultObject = createReportResultList(props);
+ operationResult.setContent((List)resultObject);
+ }
+ }
+
+ private void executeSessionOperation(ExecutedResult operationResult, final String operationName, final Map valueMap)
+ throws ConnectionException {
+ if (operationName.equals(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session.Query.GET_SESSIONS)) {
+ Object resultObject = new Object();
+
+ List fieldNameList = operationResult.getFieldNameList();
+ resultObject = getSessions(false, fieldNameList);
+ operationResult.setContent((List)resultObject);
+ }
+
+
+ }
+
+ private void executeQueriesOperation(ExecutedResult operationResult, final String operationName, final Map valueMap)
+ throws ConnectionException {
+
+ if (operationName.equals(Query.GET_QUERIES)) {
+ Object resultObject = new Object();
+
+ // Boolean includeSourceQueries = (Boolean)valueMap.get(ConnectionConstants.ComponentType.Operation.Value.INCLUDE_SOURCE_QUERIES);
+ List fieldNameList = operationResult.getFieldNameList();
+ resultObject = getRequests(false, fieldNameList);
+ operationResult.setContent((List)resultObject);
+ }
+ }
+
+
+ public Object getMetric(String componentType, String identifier, String metric, Map valueMap)
+ throws ConnectionException {
+ Object resultObject = new Object();
+
+ if (componentType.equals(ComponentType.Runtime.System.TYPE)){
+ resultObject = getSystemMetric(componentType, metric, valueMap);
+ }else if (componentType.equals(Runtime.Process.TYPE)){
+ resultObject = getProcessMetric(componentType, identifier, metric, valueMap);
+ }
+
+
+ return resultObject;
+ }
+
+ private Object getSystemMetric(String componentType, String metric,
+ Map valueMap) throws ConnectionException {
+
+ Object resultObject = new Object();
+
+ if (metric.equals(Metrics.QUERY_COUNT)) {
+ resultObject = new Double(getQueryCount().doubleValue());
+ } else {
+ if (metric.equals(Metrics.SESSION_COUNT)) {
+ resultObject = new Double(getSessionCount().doubleValue());
+ } else {
+ if (metric.equals(Metrics.LONG_RUNNING_QUERIES)) {
+ Integer longRunningQueryLimit = (Integer)valueMap.get(ConnectionConstants.ComponentType.Operation.Value.LONG_RUNNING_QUERY_LIMIT);
+ Collection<Request> longRunningQueries = getLongRunningQueries(false, longRunningQueryLimit, null);
+ resultObject = new Double(longRunningQueries.size());
+ }
+ }
+ }
+
+ return resultObject;
+ }
+
+
+ private Object getProcessMetric(String componentType, String identifier, String metric,
+ Map valueMap) throws ConnectionException {
+
+ Object resultObject = new Object();
+
+ if (metric.equals(ComponentType.Metric.HIGH_WATER_MARK)) {
+ resultObject = new Double(getHighWatermark(identifier));
+ }
+
+ return resultObject;
+ }
+
+ public Boolean isAvailable(String componentType, String identifier)
+ throws ConnectionException {
+
+ try {
+
+ Admin conn = this.getConnection();
+ if (componentType
+ .equalsIgnoreCase(Runtime.Connector.TYPE)) {
+ ConnectorBinding cb = ConnectionUtil.getConnector(conn, identifier);
+ if (cb.getState() == ConnectorBinding.STATE_OPEN) {
+ return true;
+ }
+// } else if (componentType
+// .equalsIgnoreCase(Runtime.Service.TYPE)) {
+// Service svc = ConnectionUtil.getService(conn, identifier);
+// if (svc.getState() == Service.STATE_OPEN) {
+// return true;
+// }
+
+ } else if (componentType
+ .equalsIgnoreCase(Runtime.Process.TYPE)) {
+ ProcessObject vm = ConnectionUtil.getProcess(conn, identifier);
+ if (vm.isRunning()) {
+ return true;
+ }
+ } else if (componentType
+ .equalsIgnoreCase(Runtime.Host.TYPE)) {
+ Host host=ConnectionUtil.getHost(identifier, conn);
+ if (host.isRunning()) {
+ return true;
+ }
+ } else if (componentType
+ .equalsIgnoreCase(Runtime.System.TYPE)) {
+ if (conn.getSystem() != null) {
+ return true;
+ }
+ }
+ } catch (AdminException ae) {
+ invalidConnection = true;
+
+ log.error(ae.getMessage());
+ }
+
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.metamatrix.admin.api.rhq.connection.Connection#getProperty(java.lang.String,
+ * java.lang.String)
+ */
+ public String getProperty(final String identifier, final String property)
+ throws ConnectionException {
+
+ String propertyValue = null;
+
+
+// if (identifier.equals(ConnectionConstants.SYSTEM_NAME_IDENTIFIER)) {
+// Resource mmResource = (Resource) getResource(identifier,
+// getConnection());
+// propertyValue = mmResource.getPropertyValue(property);
+// }
+
+ return propertyValue;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.metamatrix.admin.api.rhq.connection.Connection#getInstallationDirectory()
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#getHost()
+ */
+ public Component getHost(String identifier) throws ConnectionException {
+
+ try {
+
+ return mapHost( ConnectionUtil.getHost(identifier, getConnection()) );
+ } catch (AdminException e) {
+ invalidConnection = true;
+ throw new ConnectionException(e.getMessage());
+ }
+
+ }
+
+ public Collection getAllHosts() throws ConnectionException {
+ Collection<Component> hostObjs = null;
+// try {
+// Collection<Host> hosts = getConnection().getHosts("*");
+// hostObjs = new ArrayList(hosts.size());
+//
+// for (Iterator<Host>it=hosts.iterator(); it.hasNext();) {
+// Host h = it.next();
+//
+// ComponentImpl chost = mapHost(h);
+//
+// hostObjs.add(chost);
+// }
+// } catch (AdminException e) {
+// invalidConnection = true;
+// throw new ConnectionException(e.getMessage());
+// }
+
+ return hostObjs;
+ }
+
+ private ComponentImpl mapHost(Host h) throws ConnectionException {
+ ComponentImpl chost = createComponent(h);
+
+ chost.addProperty(HostComponent.INSTALL_DIR, h.getPropertyValue(Host.HOST_DIRECTORY));
+ return chost;
+
+ }
+
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#getHost()
+ */
+// public Collection<Component> getServices(String vmIdentifier) throws ConnectionException {
+//
+// try {
+//
+// Collection<Service> servicesCollection = getConnection().getServices(vmIdentifier +"|*");
+//
+// Iterator<Service> iterSvc = servicesCollection.iterator();
+//
+// Collection<Component> svccomponents = new ArrayList<Component>(servicesCollection.size());
+// while (iterSvc.hasNext()) {
+// Service svc = iterSvc.next();
+//
+// Component comp = mapService(svc);
+//
+// svccomponents.add(comp);
+// }
+// return svccomponents;
+//
+// } catch (AdminException e) {
+// invalidConnection = true;
+// throw new ConnectionException(e.getMessage());
+// }
+//
+// }
+//
+
+// public Collection<Component> getServicesForConfig(String identifier)
+// throws ConnectionException {
+// try {
+//
+// Collection<Service> servicesCollection = getConnection().getServicesToConfigure(identifier);
+//
+// Iterator<Service> iterSvc = servicesCollection.iterator();
+//
+// Collection<Component> svccomponents = new ArrayList<Component>(servicesCollection.size());
+// while (iterSvc.hasNext()) {
+// Service svc = iterSvc.next();
+//
+// Component comp = mapService(svc);
+//
+// svccomponents.add(comp);
+// }
+// return svccomponents;
+//
+// } catch (AdminException e) {
+// invalidConnection = true;
+// throw new ConnectionException(e.getMessage());
+// }
+//
+// }
+
+ public Collection<Component> getVMs(String hostIdentifier) throws ConnectionException {
+
+ try {
+
+ Collection processes = getConnection().getProcesses(hostIdentifier + "|*");
+
+ Iterator<ProcessObject> iterVMs = processes.iterator();
+ log.info("Processing processes..."); //$NON-NLS-1$
+
+ Collection vmcomponents = new ArrayList(processes.size());
+ while (iterVMs.hasNext()) {
+ // ProcessObject processObject = iterHostProcesses.next();
+ ProcessObject vm = iterVMs.next();
+
+ Component comp = mapProcess(vm);
+
+ vmcomponents.add(comp);
+ }
+
+ return vmcomponents;
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ }
+ }
+
+ private Component mapProcess(ProcessObject vm) throws ConnectionException {
+ if (vm == null) return null;
+
+ ComponentImpl comp = createComponent(vm);
+ comp.setPort(vm.getPropertyValue(ProcessObject.SERVER_PORT));
+
+ return comp;
+
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getVMs()
+ */
+// public Collection<Component> getVMs() throws ConnectionException {
+//
+// return getVMs(this.getHost().getIdentifier());
+//
+// }
+
+ /**
+ * Returns a collection of all VDBs in the system.
+ * @param fieldNameList - operaration result fields if required. May be null.
+ *
+ * @return Collection
+ */
+ public Collection getVDBs(List fieldNameList)
+ throws ConnectionException {
+
+ Collection vdbCollection = Collections.EMPTY_LIST;
+
+ try {
+
+ vdbCollection = getConnection().getVDBs("*");
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ }
+
+ if (fieldNameList != null) {
+ Collection reportResultCollection = createReportResultList(
+ fieldNameList, vdbCollection.iterator());
+ return reportResultCollection;
+ } else {
+ return vdbCollection;
+ }
+ }
+
+
+
+// public Collection<Component> getConnectorsForConfig(String identifier)
+// throws ConnectionException {
+//
+// Collection<Component> connectors = Collections.EMPTY_LIST;
+//
+// try {
+// Collection connectorsCollection = getConnection().getConnectorBindingsToConfigure(identifier);
+//
+// Iterator<ConnectorBinding> iterConnectors = connectorsCollection.iterator();
+// log.info("Getting connector bindings for configuration...");//$NON-NLS-1$
+//
+// while (iterConnectors.hasNext()) {
+// // ProcessObject processObject = iterHostProcesses.next();
+// ConnectorBinding connectorBinding = iterConnectors.next();
+//
+// log.debug("Found connector binding " + connectorBinding.getName());//$NON-NLS-1$
+//
+// Component comp = mapConnector(connectorBinding);
+//
+// connectors.add(comp);
+// }
+// return connectors;
+// } catch (AdminException e) {
+// invalidConnection = true;
+// throw new ConnectionException(e.getMessage());
+// }
+//
+// }
+
+ public Collection<Component> getConnectors(String vmIdentifier) throws ConnectionException {
+
+ Collection<Component> connectors = Collections.EMPTY_LIST;
+ try {
+
+ Collection mmConnectors = getConnection().getConnectorBindings(vmIdentifier +"|*");
+
+ connectors = new ArrayList(mmConnectors != null ? mmConnectors
+ .size() : 0);
+
+ Iterator<ConnectorBinding> iterConnectors = mmConnectors.iterator();
+ log.info("Processing connector bindings...");//$NON-NLS-1$
+
+ while (iterConnectors.hasNext()) {
+ // ProcessObject processObject = iterHostProcesses.next();
+ ConnectorBinding connectorBinding = iterConnectors.next();
+
+ log
+ .info("Found connector binding " + connectorBinding.getName());//$NON-NLS-1$
+
+ Component comp = mapConnector(connectorBinding);
+
+ connectors.add(comp);
+ }
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+ }
+ return connectors;
+ }
+
+ private Component getConnector(String connectorIdentifier) throws ConnectionException {
+
+
+ try {
+ ConnectorBinding connectorBinding = ConnectionUtil.getConnector(getConnection(), connectorIdentifier);
+ return mapConnector(connectorBinding);
+
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+ }
+ }
+
+// private Component getService(String svcIdentifier) throws ConnectionException {
+//
+//
+// try {
+// Service svc = ConnectionUtil.getService(getConnection(), svcIdentifier);
+// return mapService(svc);
+//
+// } catch (AdminException ae) {
+// invalidConnection = true;
+// throw new ConnectionException(ae.getMessage());
+// }
+//}
+
+ private Component mapConnector(ConnectorBinding connectorBinding) throws ConnectionException {
+ ComponentImpl comp = createComponent(connectorBinding);
+
+ comp.setDescription(connectorBinding.getDescription());
+
+ return comp;
+
+ }
+
+// private Component mapService(Service service) throws ConnectionException {
+// ComponentImpl comp = createComponent(service);
+//
+// comp.setDescription(service.getDescription());
+//
+// return comp;
+//
+// }
+
+ private Component mapSession(Session session) throws ConnectionException {
+ ComponentImpl comp = null;
+
+ try {
+ Class clzz = Class.forName(ComponentImpl.class.getName(), true, this.connectionPool.getClassLoader());
+ comp = (ComponentImpl) clzz.newInstance();
+
+ comp.setIdentifier(session.getIdentifier());
+ comp.setName(session.getSessionID());
+ comp.setSystemKey(getKey());
+ comp.setVersion("1.0"); //$NON-NLS-1$
+
+ comp.setProperties(session.getProperties());
+
+
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new ConnectionException(e.getMessage());
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new ConnectionException(e.getMessage());
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new ConnectionException(e.getMessage());
+ }
+ return comp;
+
+
+ }
+
+ // *******************
+ // Support Methods
+ // *******************
+
+ public Boolean isSystemAvailable() throws ConnectionException {
+
+ return this.isAlive();
+
+ }
+
+ private String getSystemName(final Admin adminApi) throws ConnectionException {
+ return "NoSystemName";
+// Resource mmJGroups = (Resource) getResource("JGroups", adminApi); //$NON-NLS-1$
+// return mmJGroups.getPropertyValue(SYSTEM_NAME_PROPERTY);
+ }
+
+
+ /**
+ * @throws Exception
+ */
+ // static
+// private Integer getQueuedThreadCount(Admin adminApi) throws Exception {
+//
+// ProcessObject process = ConnectionUtil.getProcess(getConnection(), processIdentifier);
+//
+// return process.getQueueWorkerPool().getQueued();
+//
+// }
+
+ /**
+ * @throws Exception
+ */
+ private void startConnector(final String connectorBindingIdentifier) throws ConnectionException {
+ try {
+ (getConnection())
+ .startConnectorBinding(connectorBindingIdentifier);
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ }
+ }
+
+ /**
+ * @throws Exception
+ */
+ private void bounceSystem(final boolean waitUntilFinished) throws ConnectionException {
+ try {
+ getConnection().restart();
+ } catch (AdminException err) {
+ throw new ConnectionException(err.getMessage());
+ }
+ }
+
+ /**
+ * @throws Exception
+ */
+ private void stopConnector(String connectorBindingIdentifier, boolean hardStop)
+ throws ConnectionException {
+ try {
+ getConnection().stopConnectorBinding(
+ connectorBindingIdentifier, hardStop);
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ }
+ }
+
+ /**
+ * @throws Exception
+ */
+ private static boolean isReachable(final String host, int port)
+ throws UnknownHostException {
+ return NetUtils.getInstance().isPortAvailable(host, port);
+ }
+
+ /**
+ * @throws Exception
+ */
+ // static
+// private Integer getThreadPoolThreadCount(final Admin adminApi)
+// throws ConnectionException {
+// Integer threadCount = new Integer(0);
+//
+// ProcessObject process = ConnectionUtil.getProcess(getConnection(), processIdentifier);
+//
+// QueueWorkerPool pool = null;
+// pool = process.getQueueWorkerPool();
+// threadCount = pool.getThreads();
+// return threadCount;
+// }
+
+ private Integer getQueryCount() throws ConnectionException {
+
+ Integer count = new Integer(0);
+
+ Collection<Request> requestsCollection = null;
+ requestsCollection = getRequests(false, null);
+
+ if (requestsCollection != null && !requestsCollection.isEmpty()) {
+ count = requestsCollection.size();
+ }
+
+ return count;
+ }
+
+ protected Collection<Request> getRequests(boolean includeSourceQueries, List fieldNameList) throws ConnectionException {
+
+ Collection<Request> requestsCollection = null;;
+
+ try {
+ Admin conn = getConnection();
+ requestsCollection = conn.getRequests(WILDCARD);
+ if (includeSourceQueries){
+ Collection<Request> sourceRequestsCollection = Collections.EMPTY_LIST;
+ sourceRequestsCollection = conn.getSourceRequests(WILDCARD);
+ requestsCollection.addAll(sourceRequestsCollection);
+ }
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ } catch (Exception e) {
+ final String msg = "Exception getting the AdminApi in getRequests: "; //$NON-NLS-1$
+ log.error(msg, e);
+ throw new ConnectionException(msg);
+ }
+
+ if (fieldNameList!=null){
+ Collection reportResultCollection = createReportResultList(fieldNameList, requestsCollection.iterator());
+ return reportResultCollection;
+ }else{
+ return requestsCollection;
+ }
+
+ }
+
+ protected void cancelRequest(String requestID) throws ConnectionException {
+
+ try {
+ getConnection().cancelRequest(requestID);
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ } catch (Exception e) {
+ final String msg = "Exception getting the AdminApi in getRequests: "; //$NON-NLS-1$
+ log.error(msg, e);
+ throw new ConnectionException(msg);
+ }
+
+ }
+
+// public Collection<Request> postProcessing(String operationName, Collection reportResultCollection) throws ConnectionException {
+//
+// if (operationName.equals(ConnectionConstants.ComponentType.Operation.GET_QUERIES)){
+// Iterator resultIter = reportResultCollection.iterator();
+// while (resultIter.hasNext()){
+// Map row = (Map)resultIter.next();
+// String createDateString = row.get("Createdate");
+// Date createDate = new Date(createDateString);
+//
+// Date current = new Date(System.nanoTime());
+// GregorianCalendar cal = new GregorianCalendar();
+// cal.add()
+// Date elapsedTime = Calendar.getInstance().add( createDate)
+// }
+// String createDateString = reportResultList.
+// }
+// return reportResultList;
+// }
+
+ protected Collection<Request> getLongRunningQueries(boolean includeSourceQueries, int longRunningValue, List fieldNameList) throws ConnectionException {
+
+ Collection<Request> requestsCollection = null;
+
+ double longRunningQueryTimeDouble = new Double(longRunningValue);
+
+ try {
+ requestsCollection = getRequests(includeSourceQueries, null);
+ } catch (Exception e) {
+ final String msg = "AdminException getting the AdminApi in getLongRunningQueries: "; //$NON-NLS-1$
+ log.error(msg, e);
+ throw new ConnectionException(msg);
+ }
+
+ Iterator<Request> requestsIter = requestsCollection.iterator();
+ while (requestsIter.hasNext()) {
+ Request request = requestsIter.next();
+ Date startTime = request.getProcessingDate();
+ // Get msec from each, and subtract.
+ long runningTime = Calendar.getInstance().getTimeInMillis() - startTime.getTime();
+
+ if (runningTime < longRunningQueryTimeDouble) {
+ requestsIter.remove();
+ }
+ }
+
+ if (fieldNameList!=null){
+ Collection reportResultCollection = createReportResultList(fieldNameList, requestsCollection.iterator());
+ return reportResultCollection;
+ }else{
+ return requestsCollection;
+ }
+ }
+
+ private Integer getSessionCount() throws ConnectionException {
+
+ Collection<Session> activeSessionsCollection = Collections.EMPTY_LIST;
+ try {
+ activeSessionsCollection = getActiveSessions();
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ } catch (Exception e) {
+ final String msg = "AdminException getting the AdminApi in getSessionCount: "; //$NON-NLS-1$
+ log.error(msg, e);
+ throw new ConnectionException(e.getMessage());
+ }
+
+ return activeSessionsCollection.size();
+ }
+
+ private Collection<Session> getActiveSessions(String identifier) throws AdminException {
+ Collection allSessionsCollection = getConnection().getSessions(identifier);
+ Collection activeSessionsCollection = new ArrayList();
+
+ Iterator<Session> allSessionsIter = allSessionsCollection
+ .iterator();
+ while (allSessionsIter.hasNext()) {
+ Session session = allSessionsIter.next();
+ if (session.getState() == MetaMatrixSessionState.ACTIVE) {
+ activeSessionsCollection.add(session);
+ }
+ }
+
+ return activeSessionsCollection;
+ }
+
+ private Collection<Session> getActiveSessions() throws AdminException {
+ Collection allSessionsCollection = getConnection().getSessions(WILDCARD);
+ Collection activeSessionsCollection = new ArrayList();
+
+ Iterator<Session> allSessionsIter = allSessionsCollection
+ .iterator();
+ while (allSessionsIter.hasNext()) {
+ Session session = allSessionsIter.next();
+ if (session.getState() == MetaMatrixSessionState.ACTIVE) {
+ activeSessionsCollection.add(session);
+ }
+ }
+
+ return activeSessionsCollection;
+ }
+
+ public Collection getSessions(boolean activeOnly, List fieldNameList) throws ConnectionException {
+
+ Collection sessionsCollection = Collections.EMPTY_LIST;
+ try {
+ if (activeOnly){
+ sessionsCollection = getActiveSessions();
+ }else{
+ sessionsCollection = getConnection().getSessions(WILDCARD);
+ }
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ } catch (Exception e) {
+ final String msg = "AdminException getting the AdminApi in getSessions: "; //$NON-NLS-1$
+ log.error(msg, e);
+ throw new ConnectionException(e.getMessage());
+ }
+
+ if (sessionsCollection != null && sessionsCollection.size() > 0) {
+ Iterator sessionsIter = sessionsCollection.iterator();
+
+ return createReportResultList(fieldNameList, sessionsIter);
+ }
+
+ return Collections.EMPTY_LIST;
+ }
+
+ private Collection createReportResultList(Properties props) {
+ Collection reportResultList = new ArrayList();
+
+ //Create list from properties and sort
+ Enumeration<Object> keys = props.keys();
+ List<String> elementList = new ArrayList();
+ while (keys.hasMoreElements()) {
+ elementList.add((String) keys.nextElement());
+ }
+
+ Collections.sort(elementList);
+
+ Iterator propsKeySetIter = elementList.iterator();
+
+ while (propsKeySetIter.hasNext()) {
+ Map reportValueMap = new HashMap();
+ String name = (String)propsKeySetIter.next();
+ Object value = props.get(name);
+ reportValueMap.put(ConnectionConstants.ComponentType.Operation.Value.NAME, name);
+ reportValueMap.put(ConnectionConstants.ComponentType.Operation.Value.VALUE, value);
+ reportResultList.add(reportValueMap);
+ }
+ return reportResultList;
+ }
+
+ private Collection createReportResultList(List fieldNameList, Iterator sessionsIter) {
+ Collection reportResultList = new ArrayList();
+
+ while (sessionsIter.hasNext()) {
+ Object object = sessionsIter.next();
+
+ Class cls = null;
+ try {
+ cls = object.getClass();
+ Iterator methodIter = fieldNameList.iterator();
+ Map reportValueMap = new HashMap();
+ while (methodIter.hasNext()) {
+ String fieldName = (String) methodIter.next();
+ String methodName = fieldName;
+ Method meth = cls.getMethod(methodName, (Class[]) null);
+ Object retObj = meth.invoke(object, (Object[]) null);
+ reportValueMap.put(fieldName, retObj);
+ }
+ reportResultList.add(reportValueMap);
+ } catch (Throwable e) {
+ System.err.println(e);
+ }
+ }
+ return reportResultList;
+ }
+
+ private Integer getHighWatermark(String processIdentifier) throws ConnectionException {
+
+ try {
+
+ ProcessObject process = ConnectionUtil.getProcess(getConnection(), processIdentifier);
+ QueueWorkerPool pool = null;
+ pool = process.getQueueWorkerPool();
+ return pool.getTotalHighwaterMark();
+
+ } catch (AdminException e) {
+ // TODO Auto-generated catch block
+ throw new ConnectionException(e.getMessage());
+
+ }
+
+ }
+
+ /**
+ * @param resourcePrefix
+ * @return
+ */
+// private Object getResource(final String resourceIdentifier,
+// final Admin adminApi) throws ConnectionException {
+//
+// Object resource = null;
+// try {
+//
+// Collection<Object> resourceCollection = getConnection()adminApi
+// .getResources(resourceIdentifier);
+// // Collection<Object> processCollection = ((ServerMonitoringAdmin)
+// // adminApi)
+// // .getProcesses(AdminObject.WILDCARD);
+// Iterator<Object> resourceIter = resourceCollection.iterator();
+//
+// while (resourceIter.hasNext()) {
+// resource = resourceIter.next();
+// }
+// } catch (AdminException ae) {
+// invalidConnection = true;
+// throw new ConnectionException(ae.getMessage());
+//
+//
+// } catch (Exception e) {
+// final String msg = "LogonException getting the AdminApi in getResource: "; //$NON-NLS-1$
+// log.error(msg, e);
+// }
+//
+// return resource;
+// }
+
+
+ /**
+ * @param resourcePrefix
+ * @return
+ */
+ private Component getProcess(final String processIdentifier) throws ConnectionException {
+
+ ProcessObject process = null;
+ try {
+
+ process = ConnectionUtil.getProcess(getConnection(), processIdentifier);
+
+ return mapProcess(process);
+
+ } catch (Exception e) {
+ final String msg = "AdminException in getProcess: "; //$NON-NLS-1$
+ log.error(msg, e);
+ throw new ConnectionException(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Return the properties for component of a specified resource type
+ * @param resourceType
+ * @param identifier
+ * @return
+ * @throws ConnectionException
+ * @since 5.5.3
+ */
+
+ public Properties getProperties(String resourceType, String identifier)
+ throws ConnectionException {
+ String className = null;
+ Component ao = null;
+ if (resourceType.equalsIgnoreCase(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Host.TYPE) ) {
+ className = Host.class.getName();
+ ao = this.getHost(identifier);
+
+ } else if (resourceType.equalsIgnoreCase(ConnectionConstants.ComponentType.Runtime.System.TYPE) ) {
+ className = SystemObject.class.getName();
+
+
+ } else if (resourceType.equalsIgnoreCase(Runtime.Process.TYPE) ) {
+ className = ProcessObject.class.getName();
+
+ ao = this.getProcess(identifier);
+
+ } else if (resourceType.equalsIgnoreCase(Runtime.Connector.TYPE) ) {
+ className = ConnectorBinding.class.getName();
+
+ ao = this.getConnector(identifier);
+// } else if (resourceType.equalsIgnoreCase(Runtime.Service.TYPE) ) {
+// className = Service.class.getName();
+//
+// ao = this.getService(identifier);
+ }
+
+ if (ao == null) {
+ throw new ConnectionException("Unable to get properties for invalid resource " + identifier + " of resource type " + resourceType); //$NON-NLS-1$
+ }
+
+ Properties props = null;
+ try {
+ Map defaults = ConnectionUtil.getPropertiesDefinitions(getConnection(), resourceType, className, identifier);
+
+ props = new Properties();
+ props.putAll(defaults);
+
+ // overlay the defined properties for the component object over the defaults
+ props.putAll(ao.getProperties());
+ } catch (AdminException ae) {
+ invalidConnection = true;
+ throw new ConnectionException(ae.getMessage());
+
+ }
+
+ return props;
+
+ }
+ /*
+
+ /**
+ * Returns the system name for the current connection
+ *
+ * @param componentName
+ * @param operationName
+ * @param parameters
+ * @return systemName
+ */
+// private String getProperty() throws Exception {
+//
+// String systemName = "NoSystemName";
+
+
+// Resource mmJGroups = (Resource) getResource("JGroups", getConnection()); //$NON-NLS-1$
+// systemName = mmJGroups.getPropertyValue("metamatrix.cluster.name"); //$NON-NLS-1$
+//
+// return systemName;
+//
+// }
+
+ private Admin getConnection() {
+ return adminApi;
+
+
+ }
+
+ private ComponentImpl createComponent(AdminObject object) throws ConnectionException {
+ if (object != null) {
+ return createComponent(object.getIdentifier(), object.getName(), object.getProperties());
+ }
+ return createComponent("NOTSET", "NAMENOTSET", null);
+
+
+
+ }
+
+
+ private ComponentImpl createComponent(String identifier, String name, Properties props) throws ConnectionException {
+
+ ComponentImpl comp = null;
+ try {
+ Class clzz = Class.forName(ComponentImpl.class.getName(), true, this.connectionPool.getClassLoader());
+ comp = (ComponentImpl) clzz.newInstance();
+
+ comp.setIdentifier(identifier);
+ comp.setName(name);
+ comp.setSystemKey(getKey());
+ comp.setVersion("1.0"); //$NON-NLS-1$
+
+ if (props != null) {
+ comp.setProperties(props);
+ }
+
+
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new ConnectionException(e.getMessage());
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new ConnectionException(e.getMessage());
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new ConnectionException(e.getMessage());
+ }
+ return comp;
+
+ }
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionUtil.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionUtil.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionUtil.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,341 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.teiid.adminapi.Admin;
+import org.teiid.adminapi.AdminException;
+import org.teiid.adminapi.ConnectorBinding;
+import org.teiid.adminapi.Host;
+import org.teiid.adminapi.ProcessObject;
+import org.teiid.adminapi.PropertyDefinition;
+import org.teiid.adminapi.Service;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Process;
+
+
+/**
+ * @since 4.3
+ */
+public class ConnectionUtil implements TeiidConnectionConstants {
+
+ private static Map<String, Map<String, Object>> defCache = new HashMap<String, Map<String, Object>>();
+
+ /**
+ * Call to find a host. The hostName passed in can be any of the
+ * the following:
+ * <li>The fully qualified host name</li>
+ * <li>The short name of the fully qualified host name</li>
+ * <li>The IP address of box</li>
+ * <li>The bind address defined in the host properties</li>
+ * <li>The general reference of localhost</li>
+ *
+ * The order of resolution will be as follows:
+ * 1. Try to match the IPAddress resolved host names to what is configured.
+ * <li>hostName matches to configured host name</li>
+ * <li>resolve hostName to an InetAddress and use its' full host name to match configured host(s)</li>
+ * <li>resolve hostName to an InetAddress and use its' short host name to match configured host(s)</li>
+ * <li>In cases where the <code>hostName</code> represents the short name and will not resolve to a longer name,
+ * convert the <code>Host</code> full name to the short name to try to match.</li>
+ * <li>match hostname to the physical address for a configurated host</li>
+ * <li>match hostname to the bindaddress for a configurated host</li>
+ * 2. Reverse the match, try matching what's configurated to host name passed
+ * <li>try using the short name of configured host to match</li>
+ * <li>try using the physical address of the configurated host match</li>
+ * <li>try using the bind address of the configured host to match</li>
+ *
+ * NOTE: This logic is duplicated from the CurrentConfiguration.findHost(). That method could not
+ * be used due to the different <code>Host</code> object types that are used.
+ *
+ * @param hostName
+ * @return Host
+ * @throws Exception
+ * @since 5.5
+ */
+// public static Host findHost(String hostName, ServerAdmin adminapi) throws AdminException {
+//
+// Host h = null;
+//
+// try {
+// // first try to match the name pas host by what was passed before
+// // substituting something else
+// h = getHost(hostName, adminapi);
+// if (h != null) {
+// return h;
+// }
+//
+// h = getHost(InetAddress.getLocalHost().getHostName(), adminapi);
+// if (h != null) {
+// return h;
+// }
+//
+//
+// // the hostName could be an IP address that we'll use to try to
+// // resolve back to the actuall host name
+// InetAddress inetAddress = InetAddress.getByName(hostName);
+//
+// // try using the fully qualified host name
+//
+// h = getHost(inetAddress.getCanonicalHostName(), adminapi);
+// if (h != null) {
+// return h;
+// }
+//
+// h = getHost(inetAddress.getHostName(), adminapi);
+// if (h != null) {
+// return h;
+// }
+//
+// // try the address
+// h = getHost(inetAddress.getHostAddress(), adminapi);
+//
+// if (h != null) {
+// return h;
+// }
+// } catch (AdminException ae) {
+// throw ae;
+// } catch (Exception e) {
+// // do nothing
+// }
+//
+//
+//
+// // 2nd try to match
+// try {
+// Collection hosts = getAllHosts(adminapi);
+// // if the host name passed in is the short name,
+// // then try to match to the Host short name
+//
+// Iterator hi = hosts.iterator();
+//
+// while (hi.hasNext()) {
+//
+// String hostAddress = h.getPropertyValue(Host.HOST_PHYSICAL_ADDRESS);
+//
+// if (hostAddress != null && hostAddress.equalsIgnoreCase(hostName)) {
+// return h;
+// }
+// String hostBindAddress = h.getPropertyValue(Host.HOST_BIND_ADDRESS);
+//
+// if (hostBindAddress.equalsIgnoreCase(hostName)) {
+// return h;
+// }
+//
+//
+// }
+//
+// } catch (AdminException ae) {
+// throw ae;
+// } catch (Exception e) {
+// // do nothing
+// }
+//
+//
+// return null;
+//
+// }
+
+ /**
+ * Called to return only 1 host
+ * @param hostName
+ * @param adminapi
+ * @return
+ * @throws AdminException
+ * @since 4.3
+ */
+ public static Host getHost(String hostIdentifier, Admin adminapi) throws AdminException {
+ // Configuring and monitoring will no longer be done thru a single connection.
+ // each host will be managed seperately
+
+
+// Collection hosts = adminapi.getHosts(hostIdentifier);
+//
+// if (hosts != null && hosts.size() == 1) {
+// // return the unique host by the hostName
+// return (Host) hosts.iterator().next();
+// }
+ // return null if no hosts were found or
+ // multiple hosts were found by that name.
+ return null;
+ }
+
+ /**
+ * Called to return all the currently defined hosts
+ * @param adminapi
+ * @return
+ * @throws AdminException
+ * @since 4.3
+ */
+// public static Collection getAllHosts(Admin adminapi) throws AdminException {
+//
+// return adminapi.getHosts("*"); //$NON-NLS-1$
+// }
+
+
+ /**
+ * @param adminApi is the connection to the MM Server
+ * @return Collection of MMProcesses
+ */
+// public static Collection getAllProcesses(final Admin adminApi, String identifier) throws AdminException {
+//
+// Collection processCollection = Collections.EMPTY_LIST;
+//
+// processCollection = adminApi.getProcesses(identifier + "|*"); //$NON-NLS-1$
+//
+// return processCollection;
+// }
+
+ public static ProcessObject getProcess(final Admin adminApi, String processIdentifier) throws AdminException {
+
+ Collection processCollection = adminApi.getProcesses(processIdentifier);
+
+ if (processCollection != null && processCollection.size() == 1) {
+ // return the unique connector binding
+ return (ProcessObject) processCollection.iterator().next();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param adminApi is the connection to the MM Server
+ * @return Collection of MMProcesses
+ */
+// public static Collection getAllConnectors(final Admin adminApi, String vmIdentifier) throws AdminException {
+//
+// Collection connectorCollection = Collections.EMPTY_LIST;
+//
+// connectorCollection = adminApi.getConnectorBindings(vmIdentifier +"|*");
+//
+//
+// return connectorCollection;
+// }
+
+ public static ConnectorBinding getConnector(final Admin adminApi, String cbIdentifier) throws AdminException {
+
+ Collection connectorCollection = adminApi.getConnectorBindings(cbIdentifier);
+
+ if (connectorCollection != null && connectorCollection.size() == 1) {
+ // return the unique connector binding
+ return (ConnectorBinding) connectorCollection.iterator().next();
+ }
+
+ return null;
+ }
+
+ public static Service getService(final Admin adminApi, String svcIdentifier) throws AdminException {
+
+// Collection svcCollection = adminApi.getServices(svcIdentifier);
+//
+// if (svcCollection != null && svcCollection.size() == 1) {
+// // return the unique connector binding
+// return (Service) svcCollection.iterator().next();
+// }
+
+ return null;
+ }
+
+
+ /**
+ * @param adminApi is the connection to the MM Server
+ *
+ * @return Collection of VDBs
+ */
+// public static Collection getAllVDBs(final Admin adminApi) throws AdminException {
+//
+// Collection connectorCollection = Collections.EMPTY_LIST;
+//
+// connectorCollection = adminApi.getVDBs("*"); //$NON-NLS-1$
+//
+// return connectorCollection;
+// }
+
+ /*
+ * Return the tokens in a string in a list. This is particularly
+ * helpful if the tokens need to be processed in reverse order. In that case,
+ * a list iterator can be acquired from the list for reverse order traversal.
+ *
+ * @param str String to be tokenized
+ * @param delimiter Characters which are delimit tokens
+ * @return List of string tokens contained in the tokenized string
+ */
+ public static List getTokens(String str, String delimiter) {
+ ArrayList l = new ArrayList();
+ StringTokenizer tokens = new StringTokenizer(str, delimiter);
+ while(tokens.hasMoreTokens()) {
+ l.add(tokens.nextToken());
+ }
+ return l;
+ }
+
+
+ public static synchronized Map getPropertiesDefinitions(final Admin adminApi, String resourceType, String className, String identifier) throws AdminException, ConnectionException {
+ Properties result = new Properties();
+
+ boolean cache = false;
+ if ( resourceType.equalsIgnoreCase(org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Host.TYPE) ||
+ resourceType.equalsIgnoreCase(Process.TYPE) ) {
+ cache = true;
+
+ if (defCache.containsKey(className)) {
+ return defCache.get(className);
+ }
+ }
+
+
+ Collection pdefs = adminApi.getPropertyDefinitions(identifier, className);
+
+ Map<String, Object> defMap = new HashMap<String, Object>();
+
+ for (Iterator it=pdefs.iterator(); it.hasNext();) {
+ PropertyDefinition pdef = (PropertyDefinition)it.next();
+ Object value = pdef.getValue() != null ? pdef.getValue() : pdef.getDefaultValue();
+ defMap.put(pdef.getName(), (value != null ? value : "")); //$NON-NLS-1$
+
+ }
+
+ if (cache) {
+ defCache.put(className, defMap);
+ }
+
+
+ return defMap;
+ }
+
+ static class InvalidAdminException extends Throwable {
+
+ public InvalidAdminException(String msg) {
+ super(msg);
+ }
+
+ }
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/impl/ConnectionUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/impl/InvalidConnectionImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/impl/InvalidConnectionImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/impl/InvalidConnectionImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,200 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionPool;
+import org.teiid.rhq.comm.ExecutedResult;
+
+
+
+/**
+ */
+public class InvalidConnectionImpl implements
+ Connection,
+ TeiidConnectionConstants {
+
+
+ private static final Log LOG = LogFactory.getLog(InvalidConnectionImpl.class);
+
+ private static final Object METRIC=new Double(0);
+ private static final String EMPTY_STRING=""; //$NON-NLS-1$
+
+
+ private String key = EMPTY_STRING;
+ private Properties environmentProps = null;
+ private ConnectionPool connectionPool = null;
+
+ public InvalidConnectionImpl (final String key,
+ final Properties envProps,
+ final ConnectionPool pool) {
+ this.key = key;
+ this.environmentProps = envProps;
+ this.connectionPool = pool;
+ }
+
+ public boolean isValid() {
+ return false;
+ }
+ /**
+ * @see org.teiid.rhq.comm.Connection#isAlive()
+ * @since 1.0
+ */
+ public boolean isAlive() {
+ return false;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#close()
+ * @since 1.0
+ */
+ public void close() {
+ try {
+ if (connectionPool != null) {
+ connectionPool.close(this);
+ }
+
+ } catch (Exception e) {
+ LOG.error("Error returning connection to the connection pool", e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#getMetric(java.lang.String, java.lang.String, java.util.Map)
+ * @since 1.0
+ */
+ public Object getMetric(String componentType,
+ String identifier,
+ String metric,
+ Map valueMap) throws ConnectionException {
+ return METRIC;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#executeOperation(java.lang.String, java.lang.String, java.util.Map)
+ * @since 1.0
+ */
+ public void executeOperation(ExecutedResult operationResult,
+ Map argumentMap) throws ConnectionException {
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#isAvailable(java.lang.String, java.lang.String)
+ * @since 1.0
+ */
+ public Boolean isAvailable(String componentType,
+ String identifier) throws ConnectionException {
+ return false;
+ }
+
+
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#getProperties(java.lang.String, java.lang.String)
+ * @since 1.0
+ */
+ public Properties getProperties(String resourceType,
+ String identifier) throws ConnectionException {
+ return new Properties();
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#getProperty(java.lang.String, java.lang.String)
+ * @since 1.0
+ */
+ public String getProperty(String identifier,
+ String property) throws ConnectionException {
+ return EMPTY_STRING;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#getKey()
+ * @since 1.0
+ */
+ public String getKey() throws Exception {
+ return key;
+ }
+
+ /**
+ * @see org.teiid.rhq.comm.Connection#getConnectors(java.lang.String)
+ * @since 1.0
+ */
+ public Collection<Component> getConnectors(String vmname) throws ConnectionException {
+ return Collections.EMPTY_LIST;
+ }
+
+
+ public Collection<Component> getVMs(String hostname) throws ConnectionException {
+ return Collections.EMPTY_LIST;
+ }
+
+ public Collection<Component> getVDBs(List fieldNameList) throws ConnectionException {
+ return Collections.EMPTY_LIST;
+ }
+
+
+ public Collection getAllHosts() throws ConnectionException {
+ return Collections.EMPTY_LIST;
+ }
+
+ public Component getHost(String identifier) throws ConnectionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Collection<Component> getConnectorsForConfig(String vmidentifier)
+ throws ConnectionException {
+// TODO Auto-generated method stub
+return Collections.EMPTY_LIST;
+}
+
+public Collection<Component> getServices(String vmIdentifier)
+ throws ConnectionException {
+// TODO Auto-generated method stub
+return Collections.EMPTY_LIST;
+}
+
+public Collection<Component> getServicesForConfig(String identifier)
+ throws ConnectionException {
+// TODO Auto-generated method stub
+return Collections.EMPTY_LIST;
+}
+
+public Collection<Component> discoverComponents(String componentType,
+ String identifier) throws ConnectionException {
+ // TODO Auto-generated method stub
+ return Collections.EMPTY_LIST;
+}
+
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/impl/InvalidConnectionImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/impl/NetUtils.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/impl/NetUtils.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/impl/NetUtils.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,172 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.rhq.comm.impl;
+
+import java.io.IOException;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
+
+
+public class NetUtils {
+ private InetAddress inetAddress;
+
+ private static NetUtils INSTANCE = new NetUtils();
+
+ public static NetUtils getInstance() {
+ return INSTANCE;
+ }
+
+ public InetAddress getInetAddress() throws UnknownHostException {
+ resolveHostName();
+ return this.inetAddress;
+ }
+
+
+ /**
+ * Resolves the given host name into InetAddress; if host name can not be resolved then it will
+ * throw {@link UnknownHostException}
+ * @param hostName
+ * @return
+ * @throws UnknownHostException
+ */
+ public static InetAddress resolveHostByName(String hostName) throws UnknownHostException {
+ if( hostName.equalsIgnoreCase("localhost")) { //$NON-NLS-1$
+ try {
+ return getInstance().getInetAddress();
+ } catch (UnknownHostException e) {
+ }
+ }
+ return InetAddress.getByName(hostName);
+ }
+
+ /*
+ * Dynamically resolving the host name should only be done when setupmm is being run
+ * or when the vm initially starts up and the configuration Host has to be found based on that resolution.
+ * After that, the {@link VMNaming} class should be used to obtain the logical and physical host addresses.
+ */
+ private synchronized void resolveHostName() throws UnknownHostException {
+ UnknownHostException une = null;
+
+ boolean preferIPv6=Boolean.getBoolean("java.net.preferIPv6Addresses");//$NON-NLS-1$
+
+ // majority of the times we will find the address with this below call
+ if (this.inetAddress == null) {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ if(!addr.isLoopbackAddress()) {
+ this.inetAddress = addr;
+ }
+ } catch(UnknownHostException e) {
+ une=e;
+ }
+ }
+
+ // see if you can find a non-loopback address, based on the preference
+ if (this.inetAddress == null) {
+ this.inetAddress = findAddress(preferIPv6, false);
+ }
+
+ // if no-addresses found so far then resort to IPv4 loopback address
+ if (this.inetAddress == null) {
+ this.inetAddress = findAddress(false, true);
+ }
+
+ if (this.inetAddress == null) {
+ if (une != null) throw une;
+ throw new UnknownHostException("failed to resolve the address for localhost"); //$NON-NLS-1$
+ }
+ }
+
+
+
+ /**
+ * Finds a InetAddress of the current host where the JVM is running, by querying NetworkInterfaces installed
+ * and filters them by given preferences. It will return the first Address which UP and meets the criteria
+ * @param preferIPv6
+ * @param perferLoopback
+ * @return null is returned if requested criteria is not met.
+ * @throws UnknownHostException
+ * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4665037 (Linux issue with resolving to loopback in the DHCP situations)
+ */
+ private InetAddress findAddress(boolean preferIPv6, boolean perferLoopback) throws UnknownHostException {
+ try {
+ Enumeration<NetworkInterface> ne = NetworkInterface.getNetworkInterfaces();
+ while (ne.hasMoreElements()) {
+ NetworkInterface ni = ne.nextElement();
+ //## JDBC4.0-begin ##
+ if (ni.isUp()) {
+ //## JDBC4.0-end ##
+ Enumeration<InetAddress> addrs = ni.getInetAddresses();
+ while (addrs.hasMoreElements()) {
+ InetAddress addr = addrs.nextElement();
+
+ boolean isIPv6 = (addr instanceof Inet6Address);
+ if (preferIPv6 == isIPv6 && perferLoopback == addr.isLoopbackAddress() ) {
+ return addr;
+ }
+ }
+ //## JDBC4.0-begin ##
+ }
+ //## JDBC4.0-end ##
+ }
+ } catch (SocketException e) {
+ // treat this as address not found and return null;
+ }
+ return null;
+ }
+
+ /**
+ * Call to determine if a port is available to be opened.
+ * This is used to determine if a port is already opened
+ * by some other process. If the port is available, then
+ * it's not in use.
+ * @param host
+ * @param port
+ * @return true if the port is not opened.
+ * @since 4.3
+ */
+ public boolean isPortAvailable(String host, int port) throws UnknownHostException {
+
+ try {
+ //using Socket to try to connect to an existing opened socket
+ Socket ss = new Socket(host, port);
+
+ try {
+ ss.close();
+ } catch (Exception ce) {
+ // it was open and considered available, then dont worry about the close error
+ }
+ return false;
+ } catch (UnknownHostException ce) {
+ throw ce;
+ } catch (IOException e) {
+ //ignore
+ }
+ return true;
+ }
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/impl/NetUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionConstants.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionConstants.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionConstants.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm.impl;
+
+import org.teiid.adminapi.AdminObject;
+
+
+/**
+ * @since 4.3
+ */
+public interface TeiidConnectionConstants {
+
+ public static final String MMPORT = "mmport"; //$NON-NLS-1$
+ public static final String PORT_DELIM = ","; //$NON-NLS-1$
+
+
+ public static String ID_DELIMITER = AdminObject.DELIMITER;
+ public static String MMPROCESS = AdminObject.DELIMITER + "MMProcess"; //$NON-NLS-1$
+ public static String WILDCARD = "*"; //$NON-NLS-1$
+ public static final String LONGRUNNINGQUERYTIME = "longRunningQueryTime"; //$NON-NLS-1$
+ public static final double MS_TO_MIN = 1.66666666666667E-05;
+ public static final String PROTOCOL = "mm://"; //$NON-NLS-1$
+
+ public static final String SSL_PROTOCOL = "mms://"; //$NON-NLS-1$
+
+ public static String defaultPort = "31000"; //$NON-NLS-1$
+
+ public static String SYSTEM_NAME_PROPERTY = "metamatrix.cluster.name"; //$NON-NLS-1$
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionFactory.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionFactory.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionFactory.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,248 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.comm.impl;
+
+/*
+ * The connection factory implementation is located here so that a new version
+ * of MetaMatrix that has different connection requirements can be dealt
+ * with on a per MM Version.
+ */
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.teiid.adminapi.Admin;
+import org.teiid.jdbc.TeiidDriver;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionFactory;
+import org.teiid.rhq.comm.ConnectionPool;
+
+import com.metamatrix.common.comm.platform.client.ServerAdminFactory;
+import com.metamatrix.common.jdbc.JDBCUtil;
+import com.metamatrix.jdbc.MMConnection;
+
+
+
+public class TeiidConnectionFactory implements
+ ConnectionFactory {
+ private static final Log LOG = LogFactory.getLog(TeiidConnectionFactory.class);
+
+ private Properties connEnv;
+ private ConnectionPool pool;
+ private String username = null;
+ private String password = null;
+ private String url = null;
+
+ public TeiidConnectionFactory() {
+
+ }
+
+ public String getURL() {
+ return url;
+ }
+
+ public Connection createConnection() throws ConnectionException {
+
+ Thread currentThread = Thread.currentThread();
+ ClassLoader threadContextLoader = currentThread.getContextClassLoader();
+ try {
+ currentThread.setContextClassLoader(pool.getClassLoader());
+
+ MMConnection mmconn = getConnection();
+
+ if (mmconn != null) {
+ ConnectionImpl conn = new ConnectionImpl(url, connEnv, pool, mmconn);
+ if (conn.isAlive()) {
+ return conn;
+ }
+
+ conn.closeSource();
+ }
+
+ return new InvalidConnectionImpl(url, connEnv, pool);
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ throw new ConnectionException(e);
+ } finally {
+ currentThread.setContextClassLoader(threadContextLoader);
+ }
+
+
+ }
+
+
+ public void initialize( final Properties env, final ConnectionPool connectionPool) throws ConnectionException {
+ this.connEnv = (Properties) env.clone();
+ this.pool = connectionPool;
+
+
+ if (pool == null || connEnv == null || connEnv.isEmpty()) {
+ throw new ConnectionException("ConnectionFactory has not been initialized properly"); //$NON-NLS-1$
+ }
+
+
+ url = connEnv.getProperty(ConnectionConstants.URL);
+ username = connEnv
+ .getProperty(ConnectionConstants.USERNAME);
+ password = connEnv
+ .getProperty(ConnectionConstants.PASSWORD);
+
+
+ if (url == null ) {
+ throw new ConnectionException("URL is not set"); //$NON-NLS-1$
+
+ }
+ if (username == null ) {
+ throw new ConnectionException("USERNAME is not set"); //$NON-NLS-1$
+
+ }
+ if (password == null ) {
+ throw new ConnectionException("PASSWORD is not set"); //$NON-NLS-1$
+
+ }
+ }
+
+
+ /**
+ * @see org.teiid.rhq.comm.ConnectionFactory#closeConnection(org.teiid.rhq.comm.Connection)
+ */
+ public void closeConnection(Connection connection) {
+ if (connection instanceof ConnectionImpl) {
+ ConnectionImpl conn = (ConnectionImpl) connection;
+ conn.closeSource();
+ } else {
+
+ connection.close();
+ }
+ }
+
+ private MMConnection getConnection() {
+ MMConnection conn = null;
+ Throwable firstexception = null;
+
+ try {
+ Properties props = new Properties();
+ props.setProperty(JDBCUtil.DATABASE, url);
+ props.setProperty(JDBCUtil.DRIVER, TeiidDriver.class.getName());
+ props.setProperty(JDBCUtil.USERNAME, username);
+ props.setProperty(JDBCUtil.PASSWORD, password);
+
+ conn = (MMConnection) JDBCUtil.createJDBCConnection(props);
+
+
+ return conn;
+ } catch (Throwable ce) {
+ if (firstexception == null) {
+ firstexception = ce;
+ }
+ }
+
+ if (firstexception != null) {
+ firstexception.printStackTrace();
+ LOG.error("Unable to connect to JBEDSP System: " + firstexception.getMessage()); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ /**
+ * @param userName
+ * @param password
+ * @param servers
+ * @return Admin
+ * @throws Exception,
+ * AdminException
+ * @since 5.5.3
+ */
+// private Admin getAdminAPI(String pusername, String ppassword, String purl)
+// throws Exception {
+//
+// String servers = null;
+//
+// com.metamatrix.common.comm.platform.client.ServerAdminFactory factory = null;
+//
+// Admin serverAdmin = null;
+//
+// try {
+// factory = ServerAdminFactory.getInstance();
+//
+// serverAdmin = factory.createAdmin(pusername, ppassword.toCharArray(),
+// purl, "RHQ"); //$NON-NLS-1$
+//
+// } catch (Throwable ae) {
+// if (ae instanceof MetaMatrixRuntimeException) {
+// Throwable child = ((MetaMatrixRuntimeException) ae).getChild();
+// if (child.getMessage().indexOf("Read timed out") > 0) { //$NON-NLS-1$
+// try {
+//
+// System.setProperty("com.metamatrix.ssl.trustStore", key + "/client/metamatrix.truststore"); //$NON-NLS-1$ //$NON-NLS-2$
+// servers = MMConnectionConstants.SSL_PROTOCOL + iNetAddress.getHostName() + ":" + pport; //$NON-NLS-1$
+// serverAdmin = factory.createAdmin(pusername, ppassword.toCharArray(),
+// servers, "RHQ");//$NON-NLS-1$
+// } catch (Exception ae2) {
+// throw ae;
+// }
+// } else {
+// throw ae;
+// }
+// } else {
+// throw new Exception(ae.getMessage());
+// }
+
+// }
+// LOG.info("Connected to JBEDSP Server using " + servers); //$NON-NLS-1$
+//
+// this.url = purl;
+//
+// return serverAdmin;
+// }
+
+
+
+ /*
+ * Return the tokens in a string in a list. This is particularly
+ * helpful if the tokens need to be processed in reverse order. In that case,
+ * a list iterator can be acquired from the list for reverse order traversal.
+ *
+ * @param str String to be tokenized
+ * @param delimiter Characters which are delimit tokens
+ * @return List of string tokens contained in the tokenized string
+ */
+ private static List getTokens(String str, String delimiter) {
+ ArrayList l = new ArrayList();
+ StringTokenizer tokens = new StringTokenizer(str, delimiter);
+ while(tokens.hasMoreTokens()) {
+ l.add(tokens.nextToken());
+ }
+ return l;
+ }
+
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/comm/impl/TeiidConnectionFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/embedded/EmbeddedConnectionMgr.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/embedded/EmbeddedConnectionMgr.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/embedded/EmbeddedConnectionMgr.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,97 @@
+package org.teiid.rhq.embedded;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.teiid.rhq.admin.ConnectionMgr;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionPool;
+import org.teiid.rhq.embedded.pool.ConnectionPoolImpl;
+import org.teiid.rhq.embedded.pool.EmbeddedConnectionConstants;
+
+
+
+public class EmbeddedConnectionMgr implements ConnectionMgr {
+ private static final Log log = LogFactory.getLog(EmbeddedConnectionMgr.class);
+
+ private ConnectionPool pool;
+ private Properties props;
+ private ClassLoader loader;
+
+ private Map<String, Connection> connectionList = new HashMap(1);
+
+
+ public Connection getConnection(String key) throws ConnectionException {
+ return pool.getConnection();
+ }
+
+
+
+ public Set<String> getInstallationSystemKeys() {
+ Set<String> keys = new HashSet<String>(1);
+ keys.add(EmbeddedConnectionConstants.SYSTEM_KEY);
+ return keys;
+ }
+
+
+
+ public Map getServerInstallations() {
+ connectionList = new HashMap(1);
+ try {
+ connectionList.put(pool.getKey(), pool.getConnection());
+ } catch (ConnectionException e) {
+ // TODO Auto-generated catch block
+ throw new InvalidPluginConfigurationException(e);
+ }
+ return connectionList;
+ }
+
+ public void shutdown() {
+
+ try {
+ pool.shutdown();
+ } catch (ConnectionException e) {
+ // TODO Auto-generated catch block
+ log.error("Error shutting down connection pool", e);
+
+ }
+ pool = null;
+
+ connectionList.clear();
+
+ }
+
+ public boolean hasServersDefined() {
+ return (pool !=null);
+ }
+
+ public void initialize(Properties props, ClassLoader cl) {
+ this.props = props;
+ this.loader = cl;
+
+ // allow override of the factory class
+ // this was put in to allow testing to set the factory
+ String factoryclass = System.getProperty(ConnectionPool.CONNECTION_FACTORY);
+ if (factoryclass != null) {
+ props.setProperty(ConnectionPool.CONNECTION_FACTORY, factoryclass);
+ }
+
+ try {
+ Class clzz = Class.forName(ConnectionPoolImpl.class.getName(), true, this.loader);
+ this.pool = (ConnectionPoolImpl) clzz.newInstance();
+ //new ConnectionPoolImpl();
+ this.pool.initialize(props, cl);
+
+ log.info("ConnectionPool created for key " + pool.getKey()); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (Throwable t) {
+ throw new InvalidPluginConfigurationException(t);
+ }
+ }
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/embedded/EmbeddedConnectionMgr.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/embedded/pool/ConnectionPoolImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/embedded/pool/ConnectionPoolImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/embedded/pool/ConnectionPoolImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,266 @@
+package org.teiid.rhq.embedded.pool;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionFactory;
+import org.teiid.rhq.comm.ConnectionPool;
+
+
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+/**
+ * Simple pooling built on JDBCUtil. Not compatible with DataSources, etc.
+ * Added due to poor 1.6 support among common connection pool implementations.
+ *
+ * TODO: Should be switched to proxool or some implementation
+ */
+public class ConnectionPoolImpl implements ConnectionPool
+
+{
+
+ public static final String WAIT_TIME_FOR_RESOURCE= "jbedsp.pool.wait.time"; //$NON-NLS-1$
+ public static final String MAXIMUM_RESOURCE_POOL_SIZE = "jbedsp.pool.maximum.size"; //$NON-NLS-1$
+ public static final String RESOURCE_TEST_INTERVAL = "jbedsp.pool.test.interval"; //$NON-NLS-1$
+
+ private final class ConnectionProxy implements InvocationHandler {
+ private Connection c;
+ private long lastTest = System.currentTimeMillis();
+ private Boolean valid = Boolean.TRUE;
+
+ public ConnectionProxy(Connection c) {
+ this.c = c;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ try {
+ if (method.getName().equals("close")) { //$NON-NLS-1$
+ boolean isShutdown = shutdown;
+ boolean success = false;
+ try {
+ if (!isShutdown) {
+ connections.add((Connection)proxy);
+ success = true;
+ }
+ } finally {
+ connectionLock.release();
+ if (!success) {
+ c.close();
+ return null;
+ }
+ }
+ if (success) {
+ return null;
+ }
+ } else if (method.getName().equals("isValid")) { //$NON-NLS-1$
+ long now = System.currentTimeMillis();
+ if (lastTest + testInterval > now) {
+ return c.isValid();
+ }
+ lastTest = now;
+ try {
+ valid = c.isAlive();
+ } catch (AbstractMethodError e) {
+ valid = c.isValid();
+ }
+ return valid;
+ }
+ return method.invoke(c, args);
+ } catch (InvocationTargetException e) {
+ valid = false;
+ throw e.getCause();
+ }
+ }
+ }
+
+ /**
+ * The default connection factory if one is not specified in the environment
+ */
+ static final String CONNECTION_FACTORY_DEFAULT=ConnectionFactory.CONNECTION_FACTORY_DEFAULT; //$NON-NLS-1$
+
+
+ private Semaphore connectionLock;
+ private ConcurrentLinkedQueue<Connection> connections = new ConcurrentLinkedQueue<Connection>();
+ private Properties p;
+ private int timeout;
+ private int testInterval;
+ private volatile boolean shutdown;
+ private ConnectionFactory factory = null;
+
+ private ClassLoader loader = null;
+
+ public void close(Connection connection) {
+
+
+ }
+
+
+
+ @Override
+ public int getAvailableConnectionCount() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+
+
+ @Override
+ public int getConnectionsInUseCount() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+
+
+ public ClassLoader getClassLoader() {
+ return this.loader;
+ }
+
+
+ public String getKey() {
+ return EmbeddedConnectionConstants.SYSTEM_KEY;
+ }
+
+
+
+ public void initialize(Properties env, ClassLoader cl) throws ConnectionException {
+ this.p = env;
+ this.loader = cl;
+ this.timeout = getIntProperty(p, WAIT_TIME_FOR_RESOURCE, 30000);
+ this.testInterval = getIntProperty(p, RESOURCE_TEST_INTERVAL, 30000);
+ this.connectionLock = new Semaphore(getIntProperty(p, MAXIMUM_RESOURCE_POOL_SIZE, 15));
+
+// liveAndUnusedTime = getIntProperty(LIVE_AND_UNUSED_TIME, DEFAULT_LIVE_AND_UNUSED_TIME);
+// cleaningInterval = getIntProperty(CLEANING_INTERVAL, DEFAULT_CLEANING_INTERVAL);
+
+
+ createFactory();
+ }
+
+
+
+ public Connection getConnection() throws ConnectionException {
+ if (shutdown) {
+ throw new ConnectionException("pool shutdown"); //$NON-NLS-1$
+ }
+ try {
+ if (!connectionLock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
+ throw new ConnectionException("Timeout waiting for connection"); //$NON-NLS-1$
+ }
+ } catch (InterruptedException e) {
+ throw new ConnectionException(e);
+ }
+ boolean releaseLock = true;
+ try {
+ boolean valid = false;
+ Connection c = connections.poll();
+ if (c != null) {
+
+ valid = c.isValid();
+ if (!valid) {
+ try {
+ factory.closeConnection(c);
+ } catch (Exception e) {
+
+ }
+ c = null;
+ }
+ }
+ if (c == null) {
+ if (shutdown) {
+ throw new ConnectionException("pool shutdown"); //$NON-NLS-1$
+ }
+ c = factory.createConnection();
+ c = (Connection) Proxy.newProxyInstance(this.loader, new Class[] {Connection.class}, new ConnectionProxy(c));
+ connections.add(c);
+ }
+
+ releaseLock = false;
+ return c;
+ } catch (ConnectionException ce) {
+ throw ce;
+ } finally {
+ if (releaseLock) {
+ connectionLock.release();
+ }
+ }
+ }
+
+ public void shutdown() {
+ this.shutdown = true;
+ Connection c = connections.poll();
+ while (c != null) {
+ try {
+ c.close();
+ } catch (Exception e) {
+
+ }
+ c = connections.poll();
+ }
+
+ }
+
+
+ private void createFactory() throws ConnectionException {
+
+ String factoryclass = p.getProperty(ConnectionPool.CONNECTION_FACTORY, CONNECTION_FACTORY_DEFAULT);
+
+ try {
+ Class<?> c = Class.forName(factoryclass, true, this.loader);
+ factory = (ConnectionFactory)c.newInstance();
+ } catch (Exception err) {
+ throw new ConnectionException(err.getMessage());
+ }
+
+ // Initialize connector instance...
+ factory.initialize(p, this);
+
+ }
+
+ public static int getIntProperty(Properties props, String propName, int defaultValue) throws ConnectionException {
+ int val = defaultValue;
+ String stringVal = props.getProperty(propName);
+ if(stringVal != null && stringVal.trim().length() > 0) {
+ try {
+ val = Integer.parseInt(stringVal);
+ } catch (NumberFormatException nfe) {
+ throw new ConnectionException(nfe.getMessage());
+ }
+ }
+ return val;
+ }
+
+
+
+}
+
+
Property changes on: trunk/console/src/main/java/org/teiid/rhq/embedded/pool/ConnectionPoolImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/embedded/pool/EmbeddedConnectionConstants.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/embedded/pool/EmbeddedConnectionConstants.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/embedded/pool/EmbeddedConnectionConstants.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.embedded.pool;
+
+
+/**
+ * These are the Constants that used when the jbedsp-plugin is running in the enbedded environment
+ */
+public interface EmbeddedConnectionConstants {
+
+ /**
+ * These are Environment properties need to create a connection. They will be exposed via the @see #getEnvironment call.
+ */
+ public final static String USERNAME = "username"; //$NON-NLS-1$
+ public final static String PASSWORD = "password"; //$NON-NLS-1$
+ public final static String URL = "url"; //$NON-NLS-1$
+
+
+ public final static String SYSTEM_KEY="jbedsp_system"; //$NON-NLS-1$
+
+ }
Property changes on: trunk/console/src/main/java/org/teiid/rhq/embedded/pool/EmbeddedConnectionConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/enterprise/AdminUtil.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/enterprise/AdminUtil.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/enterprise/AdminUtil.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,219 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.enterprise;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+public class AdminUtil {
+
+ private final static String[] CLASSLOADERPREFIXVALUES = new String[] {
+ "/jbedsp-teiid", "/teiid-client-", "/log4j-", "/commons-logging", "/teiid-common-core", "netty-" }; //$NON-NLS-1$, //$NON-NLS-2$, //$NON-NLS-3$, //$NON-NLS-4$
+
+ public static ClassLoader createClassloader(String installDir, ClassLoader parentClassLoader) {
+ if (true) {
+ return parentClassLoader;
+ }
+ LinkedList p = new LinkedList();
+ String[] classLoaderValues = getJarsForPrefixes(installDir + "/lib"); //$NON-NLS-1$
+ String[] patches = getPatchJars(installDir + "/lib/patches"); //$NON-NLS-1$
+ int cnt = classLoaderValues.length;
+ if (patches != null) {
+ p.addAll(Arrays.asList(patches));
+ cnt += patches.length;
+ }
+
+ p.add(installDir + "/lib/"); //$NON-NLS-1$
+ cnt++;
+
+ if (classLoaderValues != null){
+ p.addAll(Arrays.asList(classLoaderValues));
+ }
+
+ URL[] urls = new URL[cnt];
+ try {
+
+
+ for (int i = 0; i < cnt; i++) {
+ String f = (String) p.get(i);
+ urls[i] = new File(f).toURL();
+ }
+ ClassLoader classLoader = new URLClassLoader(urls, parentClassLoader);
+ return classLoader;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ // TODO: handle exception
+ }
+
+ return null;
+ }
+
+ private static String[] getJarsForPrefixes(String dir) {
+ ArrayList<String> jarArrayList = new ArrayList<String>();
+ File[] jarFiles = findAllFilesInDirectoryHavingExtension(dir, ".jar"); //$NON-NLS-1$
+ if (jarFiles != null && jarFiles.length > 0) {
+ for (int i = 0; i < jarFiles.length; i++) {
+ try {
+ String fileName = jarFiles[i].getCanonicalPath();
+ for (int j = 0; j < CLASSLOADERPREFIXVALUES.length; j++){
+ if (fileName.contains(CLASSLOADERPREFIXVALUES[j].toString())){
+ jarArrayList.add(fileName);
+ break;
+ }
+ }
+ } catch (Exception e) {
+ //TODO
+ }
+ }
+
+ }
+ String[] jars = new String[jarArrayList.size()];
+ int i = 0;
+ Iterator<String> jarIter = jarArrayList.iterator();
+ while(jarIter.hasNext()){
+ jars[i++] = jarIter.next();
+ }
+
+ return jars;
+ }
+
+ private static String[] getPatchJars(String dir) {
+ String[] jars = null;
+ File[] jarFiles = findAllFilesInDirectoryHavingExtension(dir, ".jar"); //$NON-NLS-1$
+ if (jarFiles != null && jarFiles.length > 0) {
+ jars = new String[jarFiles.length];
+ for (int i = 0; i < jarFiles.length; i++) {
+ try {
+ jars[i] = jarFiles[i].getCanonicalPath();
+ } catch (Exception e) {
+ //TODO
+ }
+ }
+
+ }
+ return jars;
+ }
+
+ /**
+ * Returns a <code>File</code> array that will contain all the files that
+ * exist in the directory that have the specified extension.
+ * @return File[] of files having a certain extension
+ */
+ private static File[] findAllFilesInDirectoryHavingExtension(String dir, final String extension) {
+
+ // Find all files in that directory that end in XML and attempt to
+ // load them into the runtime metadata database.
+ File modelsDirFile = new File(dir);
+ FileFilter fileFilter = new FileFilter() {
+ public boolean accept(File file) {
+ if(file.isDirectory()) {
+ return false;
+ }
+
+
+ String fileName = file.getName();
+
+ if (fileName==null || fileName.length()==0) {
+ return false;
+ }
+
+ // here we check to see if the file is an .xml file...
+ int index = fileName.lastIndexOf("."); //$NON-NLS-1$
+
+ if (index<0 || index==fileName.length()) {
+ return false;
+ }
+
+ if (fileName.substring(index, fileName.length()).equalsIgnoreCase(extension)) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ File[] modelFiles = modelsDirFile.listFiles(fileFilter);
+
+ return modelFiles;
+
+ }
+
+ /**
+ * Return the tokens in a string in a list. This is particularly
+ * helpful if the tokens need to be processed in reverse order. In that case,
+ * a list iterator can be acquired from the list for reverse order traversal.
+ *
+ * @param str String to be tokenized
+ * @param delimiter Characters which are delimit tokens
+ * @return List of string tokens contained in the tokenized string
+ */
+ public static List getTokens(String str, String delimiter) {
+ ArrayList l = new ArrayList();
+ StringTokenizer tokens = new StringTokenizer(str, delimiter);
+ while(tokens.hasMoreTokens()) {
+ l.add(tokens.nextToken());
+ }
+ return l;
+ }
+
+ /*
+ * Replace all occurrences of the search string with the replace string
+ * in the source string. If any of the strings is null or the search string
+ * is zero length, the source string is returned.
+ * @param source the source string whose contents will be altered
+ * @param search the string to search for in source
+ * @param replace the string to substitute for search if present
+ * @return source string with *all* occurrences of the search string
+ * replaced with the replace string
+ */
+ public static String replaceAll(String source, String search, String replace) {
+ if (source != null && search != null && search.length() > 0 && replace != null) {
+ int start = source.indexOf(search);
+ if (start > -1) {
+ StringBuffer newString = new StringBuffer(source);
+ replaceAll(newString, search, replace);
+ return newString.toString();
+ }
+ }
+ return source;
+ }
+
+ public static void replaceAll(StringBuffer source, String search, String replace) {
+ if (source != null && search != null && search.length() > 0 && replace != null) {
+ int start = source.toString().indexOf(search);
+ while (start > -1) {
+ int end = start + search.length();
+ source.replace(start, end, replace);
+ start = source.toString().indexOf(search, start + replace.length());
+ }
+ }
+ }
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/enterprise/AdminUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/enterprise/EnterpriseConnectionMgr.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/enterprise/EnterpriseConnectionMgr.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/enterprise/EnterpriseConnectionMgr.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,154 @@
+package org.teiid.rhq.enterprise;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.teiid.rhq.admin.ConnectionMgr;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionPool;
+import org.teiid.rhq.enterprise.pool.ConnectionPoolImpl;
+
+
+public class EnterpriseConnectionMgr implements ConnectionMgr {
+ private static final Log log = LogFactory.getLog(EnterpriseConnectionMgr.class);
+
+
+ public static final String INSTALL_SERVER_PROP="mmservers"; //$NON-NLS-1$
+
+ private static Map poolMap = Collections.synchronizedMap( new HashMap(5) );
+
+
+ private Properties props = null;
+
+
+ public Connection getConnection(String key) throws ConnectionException {
+ Connection connection = null;
+
+ log.info("Get Connection for " + key); //$NON-NLS-1$
+
+ ConnectionPool pool = (ConnectionPool) poolMap.get(key);
+ connection = pool.getConnection();
+
+ return connection;
+ }
+
+
+ public Set getInstallationSystemKeys() {
+ // TODO Auto-generated method stub
+ return poolMap.keySet();
+ }
+
+
+ public boolean hasServersDefined() {
+
+ if (poolMap != null && poolMap.size() > 0) {
+ return true;
+ }
+ return false;
+
+ }
+
+ public Map getServerInstallations() {
+ Map connectionList = new HashMap();
+ Iterator installationIter = poolMap.keySet().iterator();
+
+ while (installationIter.hasNext()) {
+ String installDir = (String) installationIter.next();
+ try {
+ if (poolMap.get(installDir) != null) {
+ ConnectionPool pool = (ConnectionPool) poolMap.get(installDir);
+
+ Connection connection = pool.getConnection();
+ connectionList.put(installDir, connection);
+ } else {
+ // this shouldn't happen
+ connectionList.put(installDir, null);
+ }
+ } catch (Exception e) {
+ connectionList.put(installDir, null);
+ }
+ }
+
+
+ return connectionList;
+ }
+
+
+ public void shutdown() {
+ Iterator installationIter = poolMap.keySet().iterator();
+
+ while (installationIter.hasNext()) {
+ String installDir = (String) installationIter.next();
+ ConnectionPool pool = (ConnectionPool) poolMap.get(installDir);
+ try {
+ pool.shutdown();
+ } catch (ConnectionException e) {
+ // TODO Auto-generated catch block
+ log.error("Error shutting down connection pool " + pool.getKey(), e);
+ e.printStackTrace();
+ }
+ }
+
+ poolMap.clear();
+ }
+ public void initialize(Properties props, ClassLoader cl) {
+ this.props = props;
+
+ String servers = this.props.getProperty(INSTALL_SERVER_PROP);
+
+ /**
+ * split the server installation properties by the delimiter
+ * to determine the number of servers installed on the local machine
+ */
+ Collection installationList = AdminUtil.getTokens(servers, ";"); //$NON-NLS-1$
+ Iterator installationIter = installationList.iterator();
+
+ while (installationIter.hasNext()) {
+ String serverInfoValues = (String) installationIter.next();
+ Collection serverInfoValuesList = new LinkedList();
+ serverInfoValuesList = AdminUtil.getTokens(serverInfoValues, ","); //$NON-NLS-1$
+ Object[] serverInfoArray = serverInfoValuesList.toArray();
+ String installDir = (String) serverInfoArray[0];
+ String url = (String) serverInfoArray[1];
+ String username = (String) serverInfoArray[2];
+ String password = (String) serverInfoArray[3];
+
+ props.setProperty(ConnectionConstants.PASSWORD, password);
+ props.setProperty(ConnectionConstants.USERNAME, username);
+ props.setProperty(ConnectionConstants.URL, url);
+
+ // allow override of the factory class
+ // this was put in to allow testing to set the factory
+ String factoryclass = System.getProperty(ConnectionPool.CONNECTION_FACTORY);
+ if (factoryclass != null) {
+ props.setProperty(ConnectionPool.CONNECTION_FACTORY, factoryclass);
+ }
+
+ try {
+
+ Class clzz = Class.forName(ConnectionPoolImpl.class.getName(), true, cl);
+ ConnectionPool pool = (ConnectionPool) clzz.newInstance();
+ pool.initialize(props, cl);
+
+ poolMap.put(pool.getKey(), pool);
+
+ log.info("ConnectionPool created for key " + pool.getKey() + " at url " + url); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (Throwable t) {
+ throw new InvalidPluginConfigurationException(t);
+ }
+ }
+ }
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/enterprise/EnterpriseConnectionMgr.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/ConnectionPoolImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/ConnectionPoolImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/ConnectionPoolImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,424 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.enterprise.pool;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionFactory;
+import org.teiid.rhq.comm.ConnectionPool;
+
+
+
+
+/**
+ * This is the connection pool used to manage connections to the MetaMatrix server.
+ */
+public class ConnectionPoolImpl implements ConnectionPool {
+ private final Log LOG = LogFactory.getLog(ConnectionPoolImpl.class);
+
+ /**
+ * The default connection factory if one is not specified in the environment
+ */
+ private static final String CONNECTION_FACTORY_DEFAULT=ConnectionFactory.CONNECTION_FACTORY_DEFAULT; //$NON-NLS-1$
+
+ public static final String WAIT_TIME_FOR_RESOURCE= "teiid.pool.wait.time"; //$NON-NLS-1$
+ public static final String MAXIMUM_RESOURCE_POOL_SIZE = "teiid.pool.maximum.size"; //$NON-NLS-1$
+ public static final String RESOURCE_TEST_INTERVAL = "teiid.pool.test.interval"; //$NON-NLS-1$
+
+
+ private static final int DEFAULT_LIVE_AND_UNUSED_TIME = 60;
+ private static final int DEFAULT_CLEANING_INTERVAL = 60;
+ private static final boolean DEFAULT_ENABLE_SHRINKING = true;
+
+
+ private int liveAndUnusedTime = DEFAULT_LIVE_AND_UNUSED_TIME;
+ private int cleaningInterval = DEFAULT_CLEANING_INTERVAL;
+ private boolean enableShrinking = DEFAULT_ENABLE_SHRINKING;
+
+ private int timeout;
+ private int testInterval;
+
+
+
+ private Set<ConnectionWrapper> availConnections = Collections.synchronizedSet( new HashSet(10) );
+ private Set<Connection> inuseConnections = Collections.synchronizedSet( new HashSet(10) );
+
+ private Semaphore connectionLock;
+
+ private ConnectionFactory factory = null;
+// private String installDir = null;
+ private Properties envProps = null;
+
+ private volatile boolean shuttingDownPool;
+
+ private CleanUpThread cleaningThread;
+
+ private ClassLoader clzzloader;
+
+
+ // private Object lock = new Object();
+
+ public ConnectionPoolImpl() {
+
+ LOG.info("Creating Connection Pool"); //$NON-NLS-1$
+ }
+
+
+ /**
+ * @see org.teiid.rhq.comm.ConnectionPool#getClassLoader()
+ *
+ */
+ public ClassLoader getClassLoader() {
+ return clzzloader;
+ }
+
+
+
+
+ @Override
+ public int getAvailableConnectionCount() {
+ return availConnections.size();
+ }
+
+
+
+
+ @Override
+ public int getConnectionsInUseCount() {
+ return inuseConnections.size();
+ }
+
+
+ public String getKey() {
+ // TODO Auto-generated method stub
+ return factory.getURL();
+ }
+
+
+ /**
+ * @see com.metamatrix.rhq.admin.pool.ConnectionPool#close(org.teiid.rhq.comm.Connection)
+ *
+ */
+ public void close(Connection connection) throws ConnectionException {
+ if (this.shuttingDownPool) {
+ return;
+ }
+ try {
+ if (!connectionLock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
+ throw new ConnectionException("Timeout waiting for lock"); //$NON-NLS-1$
+ }
+ } catch (InterruptedException e) {
+ throw new ConnectionException(e);
+ }
+ try {
+ inuseConnections.remove(connection);
+ if (connection.isValid()) {
+ ConnectionWrapper cw = new ConnectionWrapper(connection);
+ availConnections.add(cw);
+ LOG.debug("Connection checked in for system "); //$NON-NLS-1$
+ } else {
+ this.closeConnection(connection);
+ LOG.debug("Connection returned and closed for system "); //$NON-NLS-1$
+
+ }
+
+
+
+ } finally {
+ connectionLock.release();
+ }
+
+ }
+
+
+ /**
+ * @see com.metamatrix.rhq.admin.pool.ConnectionPool#getConnection()
+ *
+ */
+ public Connection getConnection() throws ConnectionException {
+
+ if (this.shuttingDownPool) {
+ return null;
+ }
+
+ try {
+ if (!connectionLock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
+ throw new ConnectionException("Timeout waiting for lock trying to get connection"); //$NON-NLS-1$
+ }
+ } catch (InterruptedException e) {
+ throw new ConnectionException(e);
+ }
+
+ try {
+ if (availConnections.isEmpty()) {
+ Connection conn = createConnection();
+ inuseConnections.add(conn);
+ return conn;
+ }
+
+
+ for (Iterator it=availConnections.iterator(); it.hasNext();) {
+ ConnectionWrapper conn = (ConnectionWrapper) it.next();
+ it.remove();
+ if (conn.originalConnection.isValid()) {
+ inuseConnections.add(conn.originalConnection);
+ LOG.debug("Existing connection obtained for system "); //$NON-NLS-1$
+ return conn.originalConnection;
+ }
+ this.closeConnection(conn.originalConnection);
+
+ }
+
+ Connection conn = createConnection();
+ inuseConnections.add(conn);
+ return conn;
+
+ } finally {
+ connectionLock.release();
+ }
+
+ }
+
+ /**
+ * @see com.metamatrix.rhq.admin.pool.ConnectionPool#initialize(java.lang.String, java.util.Properties)
+ *
+ */
+ public void initialize(Properties env, ClassLoader cl) throws ConnectionException {
+ this.envProps = env;
+ // this.installDir = env.getProperty(EnterpriseConnectionConstants.INSTALL_DIR);
+
+ this.clzzloader = cl;
+ this.connectionLock = new Semaphore(getIntProperty(MAXIMUM_RESOURCE_POOL_SIZE, 15));
+
+ this.timeout = getIntProperty( WAIT_TIME_FOR_RESOURCE, 30000);
+ this.testInterval = getIntProperty( RESOURCE_TEST_INTERVAL, 30000);
+ this.connectionLock = new Semaphore(getIntProperty( MAXIMUM_RESOURCE_POOL_SIZE, 15));
+
+
+ initializeProps();
+ createFactory();
+ }
+
+ /**
+ * @see com.metamatrix.rhq.admin.pool.ConnectionPool#shutdown()
+ *
+ */
+ public void shutdown() throws ConnectionException {
+ shuttingDownPool = true;
+
+ try {
+ if (!connectionLock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
+ throw new ConnectionException("Timeout waiting for lock trying to get connection"); //$NON-NLS-1$
+ }
+ } catch (InterruptedException e) {
+ throw new ConnectionException(e);
+ }
+
+ try {
+ //close cleaning thread
+ if (this.cleaningThread != null) {
+ this.cleaningThread.stopCleanup();
+ this.cleaningThread.interrupt();
+ }
+
+ // cleanup, passing true, will close all available connections
+ this.cleanUp(true);
+
+
+ for (Iterator i = inuseConnections.iterator(); i.hasNext();) {
+ Connection conn = (Connection)i.next();
+ this.closeConnection(conn);
+ }
+ inuseConnections.clear();
+
+
+
+ envProps.clear();
+ factory = null;
+ } finally {
+ connectionLock.release();
+ }
+
+
+ }
+
+
+ private void createFactory() throws ConnectionException {
+
+ String factoryclass = envProps.getProperty(ConnectionPool.CONNECTION_FACTORY, CONNECTION_FACTORY_DEFAULT);
+
+ Thread currentThread = Thread.currentThread();
+ ClassLoader threadContextLoader = currentThread.getContextClassLoader();
+ try {
+ currentThread.setContextClassLoader(this.clzzloader);
+ try {
+ Class c = Class.forName(factoryclass, true, this.clzzloader);
+ factory = (ConnectionFactory)c.newInstance();
+ } catch (Exception err) {
+ throw new ConnectionException(err.getMessage());
+ }
+
+ // Initialize connector instance...
+ factory.initialize(this.envProps, this);
+
+
+ } finally {
+ currentThread.setContextClassLoader(threadContextLoader);
+ }
+
+ }
+
+ private void initializeProps() throws ConnectionException {
+ liveAndUnusedTime = getIntProperty(LIVE_AND_UNUSED_TIME, DEFAULT_LIVE_AND_UNUSED_TIME);
+ cleaningInterval = getIntProperty(CLEANING_INTERVAL, DEFAULT_CLEANING_INTERVAL);
+
+
+ if (!this.shuttingDownPool) {
+ this.cleaningThread = new CleanUpThread(cleaningInterval * 1000);
+ this.cleaningThread.setDaemon(true);
+ this.cleaningThread.start();
+ }
+
+ String value = envProps.getProperty(ENABLE_SHRINKING);
+ if ( value != null ) {
+ enableShrinking = Boolean.valueOf(value).booleanValue();
+ }
+
+ }
+
+ private int getIntProperty(String propertyName, int defaultValue) throws ConnectionException {
+ String value = this.envProps.getProperty(propertyName );
+ if (value == null || value.trim().length() == 0) {
+ return defaultValue;
+ }
+ return Integer.parseInt(value);
+
+ }
+
+
+ private Connection createConnection() throws ConnectionException {
+ Thread currentThread = Thread.currentThread();
+ ClassLoader threadContextLoader = currentThread.getContextClassLoader();
+ try {
+ currentThread.setContextClassLoader(this.clzzloader);
+
+ // Initialize connector instance...
+ return factory.createConnection();
+
+
+ } finally {
+ currentThread.setContextClassLoader(threadContextLoader);
+ }
+
+
+
+ }
+
+ private void closeConnection(Connection conn) {
+ Thread currentThread = Thread.currentThread();
+ ClassLoader threadContextLoader = currentThread.getContextClassLoader();
+ try {
+ currentThread.setContextClassLoader(this.clzzloader);
+ // Initialize connector instance...
+ factory.closeConnection(conn);
+
+
+ } finally {
+ currentThread.setContextClassLoader(threadContextLoader);
+ }
+
+ }
+
+ protected void cleanUp(boolean forceClose) {
+ Set values = new HashSet(this.availConnections);
+
+ for (Iterator i = values.iterator(); i.hasNext();) {
+ ConnectionWrapper conn = (ConnectionWrapper)i.next();
+
+ if (forceClose || (enableShrinking && conn.getIdelTime() >= this.liveAndUnusedTime)
+ || !conn.originalConnection.isAlive()) {
+ availConnections.remove(conn);
+ this.closeConnection(conn.originalConnection);
+
+ }
+ }
+
+ }
+
+ /**
+ * ConnectionWrapper is used to store the connection in the availableConnections and
+ * will provide the amount of idletime a connection has been unused so that
+ * it can be determined if the pool can be shrunk
+ *
+ */
+ class ConnectionWrapper {
+ Connection originalConnection;
+ private long timeReturnedToPool;
+
+ ConnectionWrapper(Connection originalConn) {
+ originalConnection = originalConn;
+ timeReturnedToPool = System.currentTimeMillis();
+ }
+
+ int getIdelTime() {
+ return (int) (System.currentTimeMillis() - timeReturnedToPool) / 1000;
+ }
+ }
+
+ class CleanUpThread extends Thread {
+ private long sleepTime;
+ private boolean continueChecks = true;
+
+ CleanUpThread(long sleepTime) {
+ super("MMConnectionPoolCleanUpThread"); //$NON-NLS-1$
+ this.sleepTime = sleepTime;
+ }
+
+ public void stopCleanup() {
+ this.continueChecks = false;
+ }
+
+ public void run() {
+ while ( this.continueChecks ) {
+ try {
+ sleep(sleepTime);
+ } catch (InterruptedException e) {
+ // ignore it
+ }
+ ConnectionPoolImpl.this.cleanUp(false);
+ }
+ }
+ }
+
+
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/ConnectionPoolImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/EnterpriseConnectionConstants.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/EnterpriseConnectionConstants.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/EnterpriseConnectionConstants.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.enterprise.pool;
+
+
+/**
+ * These are the Constants that used when the jbedsp-plugin is running in the enteriprise environment
+ */
+public interface EnterpriseConnectionConstants {
+
+ /**
+ * These are Environment properties need to create a connection. They will be exposed via the @see #getEnvironment call.
+ */
+ public final static String USERNAME = "username"; //$NON-NLS-1$
+ public final static String PASSWORD = "password"; //$NON-NLS-1$
+
+ public final static String PORTS = "ports"; //$NON-NLS-1$
+ public final static String INSTALL_DIR = "install.dir"; //$NON-NLS-1$
+
+ }
Property changes on: trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/EnterpriseConnectionConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Connector;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Connector.Operations;
+
+
+/**
+ * MetaMatrix Connector component class
+ *
+ */
+public class ConnectorComponent extends Facet {
+
+ private final Log LOG = LogFactory.getLog(ConnectorComponent.class);
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 1.0
+ */
+ @Override
+ String getComponentType() {
+ return Connector.TYPE;
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map argumentMap) {
+
+ if (name.equals(Operations.STOP_CONNECTOR)){
+ Boolean stopNow = configuration.getSimple(ConnectionConstants.ComponentType.Operation.Value.STOP_NOW).getBooleanValue();
+ argumentMap.put(ConnectionConstants.ComponentType.Operation.Value.STOP_NOW, stopNow);
+ }
+ //Need identifier for all Connector operations
+ String key = ConnectionConstants.IDENTIFIER;
+ argumentMap.put(key, getComponentIdentifier());
+
+ }
+
+ @Override
+ public void getValues(MeasurementReport arg0,
+ Set<MeasurementScheduleRequest> arg1) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+// @Override
+// public OperationResult invokeOperation(String name,
+// Configuration configuration) {
+// Map valueMap = new HashMap();
+// Connection conn = null;
+//
+// Set operationDefinitionSet = this.resourceContext.getResourceType()
+// .getOperationDefinitions();
+//
+// ExecutedOperationResult result = initResult(name, operationDefinitionSet);
+//
+// setValueMap(name, configuration, valueMap);
+//
+// execute(conn, result, getComponentType(), name, valueMap);
+//
+// return ((ExecutedOperationResultImpl) result).getOperationResult();
+//
+
+// Connection conn = null;
+// Map valueMap = new HashMap();
+// MMOperationResult result = null;
+//
+// // Add "stop now" value if we are attempting to stop a connector
+// if (name.equals(ComponentType.Operation.STOP_CONNECTOR)) {
+// Boolean stopNow = configuration.getSimple(
+// ConnectionConstants.ComponentType.Operation.Value.STOP_NOW)
+// .getBooleanValue();
+// valueMap.put(
+// ConnectionConstants.ComponentType.Operation.Value.STOP_NOW,
+// stopNow);
+// }
+//
+// valueMap.put(ConnectionConstants.IDENTIFIER, getComponentIdentifier());
+//
+// try {
+// conn = getConnection();
+//
+// if (!conn.isValid()) {
+// return null;
+// }
+// // Object operationReturnObject =
+// conn.executeOperation(result,
+// getComponentType(), name, valueMap);
+//
+//
+// } catch (Exception e) {
+// final String msg = "Failed to invoke operation [" + name + "]. Cause: " + e; //$NON-NLS-1$ //$NON-NLS-2$
+// LOG.error(msg);
+// throw new RuntimeException(msg);
+// } finally {
+// conn.close();
+// }
+//
+// return (OperationResult)result;
+// }
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorDiscoveryComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorDiscoveryComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.Collection;
+
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+
+
+/**
+ * Discovery component used to discover the monitored connector bindings
+ *
+ */
+public class ConnectorDiscoveryComponent extends NodeChildrenDiscoveryComponent {
+
+ Collection<Component> getComponents(Connection conn, Facet parent) throws ConnectionException {
+ return conn.discoverComponents(ConnectionConstants.ComponentType.Runtime.Connector.TYPE, parent.getComponentIdentifier());
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/ConnectorDiscoveryComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,441 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
+import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.content.transfer.DeployPackageStep;
+import org.rhq.core.domain.content.transfer.DeployPackagesResponse;
+import org.rhq.core.domain.content.transfer.RemovePackagesResponse;
+import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.content.ContentFacet;
+import org.rhq.core.pluginapi.content.ContentServices;
+import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
+import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.core.pluginapi.operation.OperationResult;
+import org.teiid.rhq.admin.utils.SingletonConnectionManager;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ExecutedResult;
+import org.teiid.rhq.comm.VMComponent;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType;
+import org.teiid.rhq.plugin.objects.ExecutedOperationResultImpl;
+
+
+/**
+ * This class implements required RHQ interfaces and provides common logic used
+ * by all MetaMatrix components.
+ */
+public abstract class Facet implements ResourceComponent,
+ MeasurementFacet, OperationFacet, ConfigurationFacet, ContentFacet,
+ DeleteResourceFacet, CreateChildResourceFacet {
+
+ protected static SingletonConnectionManager connMgr = SingletonConnectionManager
+ .getInstance();
+
+ protected final Log LOG = LogFactory
+ .getLog(Facet.class);
+
+ /**
+ * Represents the resource configuration of the custom product being
+ * managed.
+ */
+ protected Configuration resourceConfiguration;
+
+
+ /**
+ * All AMPS plugins are stateful - this context contains information that
+ * your resource component can use when performing its processing.
+ */
+ protected ResourceContext<?> resourceContext;
+
+ private String systemKey;
+
+ private String name;
+
+ private String identifier;
+
+ // may be null when the component is not a host or vm
+ private String port = null;
+
+ protected boolean isAvailable = false;
+
+ abstract String getComponentType();
+
+ /**
+ * This is called when your component has been started with the given
+ * context. You normally initialize some internal state of your component as
+ * well as attempt to make a stateful connection to your managed resource.
+ *
+ * @see ResourceComponent#start(ResourceContext)
+ */
+ public void start(ResourceContext context) {
+ resourceContext = context;
+
+
+ systemKey = resourceContext.getPluginConfiguration()
+ .getSimpleProperties().get(Component.SYSTEM_KEY)
+ .getStringValue();
+ name = resourceContext.getPluginConfiguration().getSimpleProperties()
+ .get(Component.NAME).getStringValue();
+
+ // because the system may not be up, name and
+ // identifier may be null at initial creation
+ // and will be updated when the system becomes available.
+ if (name == null)
+ name = "NotSet"; //$NON-NLS-1$
+
+ identifier = resourceContext.getPluginConfiguration()
+ .getSimpleProperties().get(Component.IDENTIFIER)
+ .getStringValue();
+ if (identifier == null)
+ identifier = "";//$NON-NLS-1$
+ if (resourceContext.getPluginConfiguration().getSimpleProperties().get(
+ VMComponent.PORT) != null) {
+ port = resourceContext.getPluginConfiguration()
+ .getSimpleProperties().get(VMComponent.PORT)
+ .getStringValue();
+ }
+ }
+
+ /**
+ * This is called when the component is being stopped, usually due to the
+ * plugin container shutting down. You can perform some cleanup here; though
+ * normally not much needs to be done here.
+ *
+ * @see ResourceComponent#stop()
+ */
+ public void stop() {
+ this.isAvailable = false;
+ }
+
+ /**
+ * @return the resourceConfiguration
+ */
+ public Configuration getResourceConfiguration() {
+ return resourceConfiguration;
+ }
+
+ /**
+ * @param resourceConfiguration the resourceConfiguration to set
+ */
+ public void setResourceConfiguration(Configuration resourceConfiguration) {
+ this.resourceConfiguration = resourceConfiguration;
+ }
+
+ public String getSystemKey() {
+ return systemKey;
+ }
+
+ public String getComponentName() {
+ return name;
+ }
+
+ protected void setComponentName(String componentName) {
+ this.name = componentName;
+ }
+
+ public String getPort() {
+ return port;
+ }
+
+ public String getComponentIdentifier() {
+ return identifier;
+ }
+
+ protected void setComponentIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map argumentMap) {
+// moved this logic up to the associated implemented class
+ throw new InvalidPluginConfigurationException("Not implemented on component type " + this.getComponentType() + " named " + this.getComponentName());
+
+
+ }
+
+ protected void execute(final ExecutedResult result,
+ final Map valueMap) {
+ Connection conn = null;
+ try {
+ conn = getConnection();
+
+ if (!conn.isValid()) {
+ return;
+ }
+ conn.executeOperation(result, valueMap);
+
+ } catch (Exception e) {
+ final String msg = "Error invoking operation [" + name + "]. Cause: " + e; //$NON-NLS-1$ //$NON-NLS-2$
+ LOG.error(msg);
+ throw new RuntimeException(msg);
+ } finally {
+ conn.close();
+ }
+ }
+
+ /**
+ * The connection will be returned when it is available. If it is not, then
+ * null will be returned. Resource methods will not throw exceptions as a
+ * MetaMatrix System goes up and down. That state will be indicated by it's
+ * availability state.
+ *
+ * @return
+ */
+
+ public Connection getConnection() throws ConnectionException {
+ Connection conn = connMgr.getConnection(getSystemKey());
+ if (conn.isValid()) {
+ this.isAvailable = true;
+ } else {
+ this.isAvailable = false;
+ }
+
+ return conn;
+ }
+
+ /*
+ * (non-Javadoc)
+ * This method is called by JON to check the availability of the inventoried component on a time scheduled basis
+ *
+ * @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability()
+ */
+ public AvailabilityType getAvailability() {
+
+ if (!connMgr.hasServersDefined()) {
+ this.isAvailable = false;
+ return AvailabilityType.DOWN;
+
+ }
+ Connection connection = null;
+ try {
+
+ LOG.debug("Checking availability of " + identifier); //$NON-NLS-1$
+ connection = getConnection();
+ if (connection.isAvailable(getComponentType(), identifier)) {
+ LOG.info("Availability of " + identifier + " is up"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.isAvailable = true;
+ return AvailabilityType.UP;
+ }
+ } catch (InvalidPluginConfigurationException ipce) {
+ // dont log anything, already done when getconnection is called
+ } catch (Throwable err) {
+ LOG.error("Unknown exception occured when checking availability for resource " + identifier, err); //$NON-NLS-1$
+ } finally {
+ connection.close();
+ }
+ LOG.error("Availability of " + identifier + " is down"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.isAvailable = false;
+ return AvailabilityType.DOWN;
+ }
+
+ /**
+ * Helper method that indicates the latest status based on the last
+ * getAvailabilit() call.
+ *
+ * @return true if the resource is available
+ */
+ protected boolean isAvailable() {
+ return this.isAvailable;
+ }
+
+ /**
+ * The plugin container will call this method when your resource component
+ * has been scheduled to collect some measurements now. It is within this
+ * method that you actually talk to the managed resource and collect the
+ * measurement data that is has emitted.
+ *
+ * @see MeasurementFacet#getValues(MeasurementReport, Set)
+ */
+ public abstract void getValues(MeasurementReport arg0,
+ Set<MeasurementScheduleRequest> arg1) throws Exception;
+
+ /**
+ * The plugin container will call this method when it wants to invoke an
+ * operation on your managed resource. Your plugin will connect to the
+ * managed resource and invoke the analogous operation in your own custom
+ * way.
+ *
+ * @see OperationFacet#invokeOperation(String, Configuration)
+ */
+ public OperationResult invokeOperation(String name,
+ Configuration configuration) {
+ Map valueMap = new HashMap();
+ Connection conn = null;
+
+ Set operationDefinitionSet = this.resourceContext.getResourceType()
+ .getOperationDefinitions();
+
+
+ ExecutedResult result = new ExecutedOperationResultImpl(
+ this.getComponentType(),
+ name,
+ operationDefinitionSet);
+
+ setOperationArguments(name, configuration, valueMap);
+
+ execute(result, valueMap);
+
+ return ((ExecutedOperationResultImpl) result).getOperationResult();
+
+ }
+
+ /**
+ * The plugin container will call this method and it needs to obtain the
+ * current configuration of the managed resource. Your plugin will obtain
+ * the managed resource's configuration in your own custom way and populate
+ * the returned Configuration object with the managed resource's
+ * configuration property values.
+ *
+ * @see ConfigurationFacet#loadResourceConfiguration()
+ */
+ public Configuration loadResourceConfiguration() {
+ // here we simulate the loading of the managed resource's configuration
+
+ if (resourceConfiguration == null) {
+ // for this example, we will create a simple dummy configuration to
+ // start with.
+ // note that it is empty, so we're assuming there are no required
+ // configs in the plugin descriptor.
+ resourceConfiguration = new Configuration();
+ }
+
+ Configuration config = resourceConfiguration;
+
+ return config;
+ }
+
+ /**
+ * The plugin container will call this method when it has a new
+ * configuration for your managed resource. Your plugin will re-configure
+ * the managed resource in your own custom way, setting its configuration
+ * based on the new values of the given configuration.
+ *
+ * @see ConfigurationFacet#updateResourceConfiguration(ConfigurationUpdateReport)
+ */
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ // this simulates the plugin taking the new configuration and
+ // reconfiguring the managed resource
+ resourceConfiguration = report.getConfiguration().deepCopy();
+
+ report.setStatus(ConfigurationUpdateStatus.SUCCESS);
+ }
+
+ /**
+ * When this is called, the plugin is responsible for scanning its managed
+ * resource and look for content that need to be managed for that resource.
+ * This method should only discover packages of the given package type.
+ *
+ * @see ContentFacet#discoverDeployedPackages(PackageType)
+ */
+ public Set<ResourcePackageDetails> discoverDeployedPackages(PackageType type) {
+ return null;
+ }
+
+ /**
+ * The plugin container calls this method when new packages need to be
+ * deployed/installed on resources.
+ *
+ * @see ContentFacet#deployPackages(Set, ContentServices)
+ */
+ public DeployPackagesResponse deployPackages(
+ Set<ResourcePackageDetails> packages,
+ ContentServices contentServices) {
+ return null;
+ }
+
+ /**
+ * When a remote client wants to see the actual data content for an
+ * installed package, this method will be called. This method must return a
+ * stream of data containing the full content of the package.
+ *
+ * @see ContentFacet#retrievePackageBits(ResourcePackageDetails)
+ */
+ public InputStream retrievePackageBits(ResourcePackageDetails packageDetails) {
+ return null;
+ }
+
+ /**
+ * This is the method that is used when the component has to create the
+ * installation steps and their results.
+ *
+ * @see ContentFacet#generateInstallationSteps(ResourcePackageDetails)
+ */
+ public List<DeployPackageStep> generateInstallationSteps(
+ ResourcePackageDetails packageDetails) {
+ return null;
+ }
+
+ /**
+ * This is called when the actual content of packages should be deleted from
+ * the managed resource.
+ *
+ * @see ContentFacet#removePackages(Set)
+ */
+ public RemovePackagesResponse removePackages(
+ Set<ResourcePackageDetails> packages) {
+ return null;
+ }
+
+ /**
+ * When called, the plugin container is asking the plugin to create a new
+ * managed resource. The new resource's details need to be added to the
+ * given report.
+ *
+ * @see CreateChildResourceFacet#createResource(CreateResourceReport)
+ */
+ public CreateResourceReport createResource(CreateResourceReport report) {
+ return null;
+ }
+
+ /**
+ * When called, the plugin container is asking the plugin to delete a
+ * managed resource.
+ *
+ * @see DeleteResourceFacet#deleteResource()
+ */
+ public void deleteResource() {
+ }
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/HostComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/HostComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/HostComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,176 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.measurement.MeasurementFacet;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Host;
+
+
+/**
+ * Component class for the MetaMatrix Host Controller process.
+ *
+ */
+public class HostComponent extends Facet {
+ private final Log LOG = LogFactory
+ .getLog(HostComponent.class);
+
+
+ public static final String CONNECTOR_ADDRESS_CONFIG_PROPERTY = "connectorAddress"; //$NON-NLS-1$
+
+ public static final String CONNECTION_TYPE = "type"; //$NON-NLS-1$
+
+ public static final String PARENT_TYPE = "PARENT"; //$NON-NLS-1$
+
+ public static final String INSTALL_DIR = "install.dir"; //$NON-NLS-1$
+
+
+ private String install_dir;
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 1.0
+ */
+ @Override
+ String getComponentType() {
+ return Host.TYPE;
+ }
+
+
+
+ String getInstallDirectory() {
+
+ if (install_dir != null) {
+ return install_dir;
+ }
+ install_dir = resourceContext.getPluginConfiguration()
+ .getSimpleProperties().get(INSTALL_DIR)
+ .getStringValue();
+
+ return install_dir;
+ }
+
+
+ /**
+ * The plugin container will call this method when your resource component
+ * has been scheduled to collect some measurements now. It is within this
+ * method that you actually talk to the managed resource and collect the
+ * measurement data that is has emitted.
+ *
+ * @see MeasurementFacet#getValues(MeasurementReport, Set)
+ */
+ public void getValues(MeasurementReport report,
+ Set<MeasurementScheduleRequest> requests) {
+ for (MeasurementScheduleRequest request : requests) {
+ String name = request.getName();
+
+ // TODO: based on the request information, you must collect the
+ // requested measurement(s)
+ // you can use the name of the measurement to determine what you
+ // actually need to collect
+ try {
+ Number value = new Integer(1); // dummy measurement value -
+ // this should come from the
+ // managed resource
+ report.addData(new MeasurementDataNumeric(request, value
+ .doubleValue()));
+ } catch (Exception e) {
+ LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
+ + "]. Cause: " + e); //$NON-NLS-1$
+ }
+ }
+
+ return;
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map argumentMap) {
+
+ if (name.equals(ConnectionConstants.ComponentType.Operation.GET_PROPERTIES)){
+ String key = ConnectionConstants.IDENTIFIER;
+ argumentMap.put(key, getComponentIdentifier());
+ }
+
+ }
+
+ /**
+ * The plugin container will call this method and it needs to obtain the
+ * current configuration of the managed resource. Your plugin will obtain
+ * the managed resource's configuration in your own custom way and populate
+ * the returned Configuration object with the managed resource's
+ * configuration property values.
+ *
+ * @see ConfigurationFacet#loadResourceConfiguration()
+ *
+ */
+ @Override
+ public Configuration loadResourceConfiguration() {
+ // here we simulate the loading of the managed resource's configuration
+ Configuration config = this.getResourceConfiguration() ;
+ if (config == null) {
+ // for this example, we will create a simple dummy configuration to
+ // start with.
+ // note that it is empty, so we're assuming there are no required
+ // configs in the plugin descriptor.
+ config = new Configuration();
+ }
+
+ Properties props;
+ try {
+ props = getConnection().getProperties(this.getComponentType(), this.getComponentIdentifier());
+ } catch (ConnectionException e) {
+ LOG.error("Failed to obtain host properties for [" + this.getComponentIdentifier() //$NON-NLS-1$
+ + "]. Cause: " + e); //$NON-NLS-1$
+ throw new InvalidPluginConfigurationException(e);
+ }
+
+ if (props != null && props.size() > 0) {
+ Iterator it=props.keySet().iterator();
+ while(it.hasNext()) {
+ String k = (String)it.next();
+
+ config.put(new PropertySimple(k, props.get(k)));
+
+ }
+
+ }
+
+
+ this.setResourceConfiguration(config);
+ return this.getResourceConfiguration();
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/HostComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/HostDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/HostDiscoveryComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/HostDiscoveryComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.Collection;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+
+
+/**
+ * Discovery component for the MetaMatrix Host controller process
+ *
+ */
+public class HostDiscoveryComponent extends NodeChildrenDiscoveryComponent {
+
+
+ @Override
+ Collection<Component> getComponents(Connection conn, Facet parent) throws ConnectionException {
+ return conn.discoverComponents(ConnectionConstants.ComponentType.Runtime.Host.TYPE, "*");
+ }
+
+ @Override
+ protected void addAdditionalProperties(Configuration configuration, Component component) throws InvalidPluginConfigurationException {
+ String installdir = component.getProperty(HostComponent.INSTALL_DIR);
+ configuration.put(new PropertySimple(HostComponent.INSTALL_DIR,
+ installdir));
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/HostDiscoveryComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+
+
+/**
+ * Discovery component used to discover the monitored connector bindings
+ *
+ */
+public abstract class NodeChildrenDiscoveryComponent extends NodeDiscoveryComponent {
+
+
+ private final Log LOG = LogFactory.getLog(NodeChildrenDiscoveryComponent.class);
+
+ /**
+ * @see ResourceDiscoveryComponent#discoverResources(ResourceDiscoveryContext)
+ */
+
+ @Override
+ protected void addResources(Set<DiscoveredResourceDetails> found, ResourceType resourceType, Facet parent)
+ throws InvalidPluginConfigurationException {
+ Connection conn = null;
+ try {
+ conn = getConnection();
+ if (!conn.isValid()) {
+ return;
+ }
+ Collection<Component> components = getComponents(conn, parent);
+
+ if (components == null || components.size() == 0) {
+ LOG.info("No components were found to be configured for parent "+ parent.getComponentIdentifier()); //$NON-NLS-1$
+ return;
+ }
+
+ Iterator<Component> comIter = components.iterator();
+
+ while (comIter.hasNext()) {
+ Component comp = comIter.next();
+ LOG.info("Processing component "+ comp.getName()); //$NON-NLS-1$
+
+ DiscoveredResourceDetails resource = this.createResource(resourceType, comp);
+
+ found.add(resource);
+ }
+ } catch (InvalidPluginConfigurationException ipe) {
+ throw ipe;
+ } catch (Throwable t) {
+ throw new InvalidPluginConfigurationException(t);
+
+ } finally {
+ if (conn != null) {
+ conn.close();
+ }
+ }
+
+
+ }
+
+ protected DiscoveredResourceDetails createResource(ResourceType resourceType, Component component)
+ throws InvalidPluginConfigurationException {
+
+ DiscoveredResourceDetails resource = createResource(resourceType,
+ systemkey + "|" + component.getIdentifier(),
+ component.getName(),
+ (component.getDescription()!=null?component.getDescription():""));
+
+
+ Configuration configuration = resource.getPluginConfiguration();
+ configuration.put(new PropertySimple(Component.NAME, component.getName()));
+ configuration.put(new PropertySimple(Component.IDENTIFIER, component.getIdentifier()));
+ configuration.put(new PropertySimple(Component.SYSTEM_KEY, systemkey));
+
+ addAdditionalProperties(configuration, component);
+
+ return resource;
+
+ }
+
+ protected void addAdditionalProperties(Configuration configuration, Component component) throws InvalidPluginConfigurationException {
+
+ }
+
+ abstract Collection<Component> getComponents(Connection conn, Facet parent) throws ConnectionException;
+
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/NodeChildrenDiscoveryComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.teiid.rhq.admin.utils.SingletonConnectionManager;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+
+
+/**
+ * Discovery component used to discover the monitored services
+ *
+ */
+public class NodeDiscoveryComponent implements
+ ResourceDiscoveryComponent {
+ private static final Log LOG = LogFactory
+ .getLog(NodeDiscoveryComponent.class);
+
+ private static SingletonConnectionManager connMgr = SingletonConnectionManager.getInstance();
+
+ protected String systemkey = null;
+
+
+ public Set<DiscoveredResourceDetails> discoverResources(
+ ResourceDiscoveryContext discoveryContext) throws InvalidPluginConfigurationException, Exception {
+
+
+ String name = discoveryContext.getResourceType().getName();
+
+ LOG.info("Discovering " + name); //$NON-NLS-1$
+
+ // if no servers have been defined, do not discover resources
+ if (!connMgr.hasServersDefined()) {
+ LOG.info("Unable to discover " + name + ", no JBEDSP Platforms defined"); //$NON-NLS-1$
+ return Collections.EMPTY_SET;
+ }
+
+ Facet parent = (Facet) discoveryContext.getParentResourceComponent();
+
+ String parentName = parent.getComponentName();
+ systemkey = parent.getSystemKey();
+
+ LOG.info("Discovering JBEDSP " + name + " for " + (parentName!=null?parentName:"PARENTNAMENOTFOUND")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Set<DiscoveredResourceDetails> found = new HashSet<DiscoveredResourceDetails>();
+
+ addResources(found, discoveryContext.getResourceType(), parent);
+
+ return found;
+ }
+
+ protected void addResources(Set<DiscoveredResourceDetails> found, ResourceType resourceType, Facet parent)
+ throws InvalidPluginConfigurationException {
+ String identifier = parent.getComponentIdentifier()+ "|" + resourceType.getName();
+ DiscoveredResourceDetails resource = createResource(resourceType, identifier, resourceType.getName(), resourceType.getDescription());
+
+ found.add(resource);
+
+ }
+
+ protected DiscoveredResourceDetails createResource(ResourceType resourceType, String identifier, String name, String description)
+ throws InvalidPluginConfigurationException {
+
+ DiscoveredResourceDetails resource = new DiscoveredResourceDetails(resourceType,
+ identifier, name,
+ ConnectionConstants.VERSION,
+ (description!=null?description:""),
+ null,
+ null);
+
+ Configuration configuration = resource.getPluginConfiguration();
+ configuration.put(new PropertySimple(Component.NAME, name));
+ configuration.put(new PropertySimple(Component.IDENTIFIER, identifier));
+ configuration.put(new PropertySimple(Component.SYSTEM_KEY, systemkey));
+
+ addAdditionalProperties(configuration);
+
+ return resource;
+
+ }
+
+
+
+ protected void addAdditionalProperties(Configuration configuration) throws InvalidPluginConfigurationException {
+
+ }
+
+ protected Connection getConnection() throws InvalidPluginConfigurationException{
+ try {
+ return connMgr.getConnection(this.systemkey);
+
+ } catch (Throwable t) {
+ throw new InvalidPluginConfigurationException(t);
+
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/NodeDiscoveryComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.teiid.rhq.admin.utils.SingletonConnectionManager;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType;
+
+
+/**
+ *
+ */
+public class PlatformComponent extends Facet {
+ private final Log LOG = LogFactory.getLog(PlatformComponent.class);
+
+ /**
+ * Property is used to identify an unreachable system
+ */
+ protected static final String UNREACHABLE_NAME = "UNREACHABLE_PLATFORM"; //$NON-NLS-1$
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 4.3
+ */
+ @Override
+ String getComponentType() {
+ return ConnectionConstants.ComponentType.PLATFORM;
+ }
+
+ @Override
+ public AvailabilityType getAvailability() {
+
+ if (!connMgr.hasServersDefined()) {
+ this.isAvailable = false;
+ return AvailabilityType.DOWN;
+
+ }
+ Connection connection = null;
+ try {
+
+ LOG.debug("Checking availability of " + this.getComponentIdentifier()); //$NON-NLS-1$
+ connection = getConnection();
+ if (connection.isAlive()) {
+ LOG.info("Availability of " + this.getComponentIdentifier() + " is up"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.isAvailable = true;
+ return AvailabilityType.UP;
+ }
+ } catch (InvalidPluginConfigurationException ipce) {
+ // dont log anything, already done when getconnection is called
+ } catch (Throwable err) {
+ LOG.error("Unknown exception occured when checking availability for resource " + this.getComponentIdentifier(), err); //$NON-NLS-1$
+ } finally {
+ connection.close();
+ }
+ LOG.error("Availability of " + this.getComponentIdentifier() + " is down"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.isAvailable = false;
+ return AvailabilityType.DOWN;
+ }
+
+
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map valueMap) {
+
+ }
+
+
+ @Override
+ public void getValues(MeasurementReport report,
+ Set<MeasurementScheduleRequest> requests) throws Exception {
+ }
+
+
+
+ @Override
+ public void stop() {
+ // TODO Auto-generated method stub
+ super.stop();
+ connMgr.shutdown();
+ }
+
+ @Override
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+
+ Properties props = System.getProperties();
+
+ Iterator<PropertySimple> pluginPropIter = report.getConfiguration().getSimpleProperties().values().iterator();
+
+ while (pluginPropIter.hasNext()){
+ PropertySimple pluginProp = pluginPropIter.next();
+ props.put(pluginProp.getName(), pluginProp.getStringValue());
+ }
+
+ SingletonConnectionManager.getInstance().initialize(props);
+ super.updateResourceConfiguration(report);
+
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.teiid.rhq.admin.utils.SingletonConnectionManager;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.ConnectionConstants;
+
+
+/**
+ * This is the parent node for a MetaMatrix system
+ */
+public class PlatformDiscoveryComponent implements ResourceDiscoveryComponent {
+ private static SingletonConnectionManager connMgr = SingletonConnectionManager.getInstance();
+ private static final Log LOG = LogFactory
+ .getLog(PlatformDiscoveryComponent.class);
+
+
+ Map environmentMap = new HashMap();
+
+ /**
+ * Review the javadoc for both {@link ResourceDiscoveryComponent} and
+ * {@link ResourceDiscoveryContext} to learn what you need to do in this
+ * method.
+ *
+ * @see ResourceDiscoveryComponent#discoverResources(ResourceDiscoveryContext)
+ */
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext discoveryContext) throws InvalidPluginConfigurationException,
+ Exception {
+ try {
+
+ String name = discoveryContext.getResourceType().getName();
+ String desc = discoveryContext.getResourceType().getDescription();
+ String version = ConnectionConstants.VERSION;
+
+ LOG.info("Discovering " + desc); //$NON-NLS-1$
+
+
+ // now perform your own discovery mechanism, if you have one. For each
+ // resource discovered, you need to
+ // create a details object that describe the resource that you
+ // discovered.
+ HashSet<DiscoveredResourceDetails> set = new HashSet<DiscoveredResourceDetails>();
+
+ Set<String> systemkeys = null ;
+
+ try {
+ systemkeys = connMgr.getInstallationSystemKeys();
+ } catch (Exception e) {
+ systemkeys = new HashSet(1);
+ systemkeys.add("NotDefined");
+
+ // TODO
+ // - when the serverList cannot be obtained
+
+ // DO NOT throw exception, still want to create the
+ // resource, but it will show not active / available
+ }
+
+
+
+ Iterator<String> serverIter = systemkeys.iterator();
+ int hostCount = -1;
+ while (serverIter.hasNext()) {
+ hostCount++;
+ String systemKey = serverIter.next();
+
+ DiscoveredResourceDetails resource = new DiscoveredResourceDetails(discoveryContext.getResourceType(),
+ systemKey, name,
+ version, desc, null, null);
+
+ Configuration configuration = resource.getPluginConfiguration();
+ configuration.put(new PropertySimple(Component.NAME, name));
+ configuration.put(new PropertySimple(Component.IDENTIFIER, name));
+ configuration.put(new PropertySimple(Component.SYSTEM_KEY, systemKey));
+
+
+ set.add(resource);
+
+ }
+
+ return set;
+ } catch (InvalidPluginConfigurationException ipe) {
+ throw ipe;
+ } catch (Throwable t) {
+ throw new InvalidPluginConfigurationException(t);
+ }
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,316 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.event.EventSeverity;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.event.EventContext;
+import org.rhq.core.pluginapi.event.EventPoller;
+import org.rhq.core.pluginapi.event.log.LogFileEventPoller;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Process;
+import org.teiid.rhq.plugin.log.JBEDSPErrorLogEntryProcessor;
+
+
+/**
+ *
+ * MetaMatrix server component class. This class represents the node for the
+ * MMProcess.
+ *
+ */
+public class ProcessComponent extends Facet {
+ private final Log LOG = LogFactory.getLog(ProcessComponent.class);
+
+
+ public static final String PLUGIN_CONFIG_PROP_ERROR_LOG_EVENTS_ENABLED = "enabled"; //$NON-NLS-1$
+ public static final String PLUGIN_CONFIG_PROP_ERROR_LOG_MINIMUM_SEVERITY = "minimumSeverity"; //$NON-NLS-1$
+ public static final String PLUGIN_CONFIG_PROP_ERROR_LOG_INCLUDES_PATTERN = "errorLogIncludesPattern"; //$NON-NLS-1$
+ public static final String PLUGIN_CONFIG_PROP_ERROR_LOG_FILE_PATH = "errorLogFilePath"; //$NON-NLS-1$
+ public static final String INSTALL_DIR = "install.dir"; //$NON-NLS-1$
+
+ private static final String ERROR_LOG_ENTRY_EVENT_TYPE = "errorLogEntry"; //$NON-NLS-1$
+
+
+
+ private EventContext eventContext;
+ private File errorLogFile;
+
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#start(org.rhq.core.pluginapi.inventory.ResourceContext)
+ */
+ @Override
+ public void start(ResourceContext context) {
+ super.start(context);
+
+ this.eventContext = resourceContext.getEventContext();
+
+ // startEventPollers();
+ }
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#stop()
+ */
+ @Override
+ public void stop() {
+ stopEventPollers();
+ super.stop();
+
+ }
+
+ public AvailabilityType getAvailability() {
+
+ return AvailabilityType.UP;
+ }
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 1.0
+ */
+ @Override
+ String getComponentType() {
+ return Process.TYPE;
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map argumentMap) {
+
+ if (name.equals(ConnectionConstants.ComponentType.Operation.GET_PROPERTIES)){
+ String key = ConnectionConstants.IDENTIFIER;
+ argumentMap.put(key, getComponentIdentifier());
+ }
+
+ }
+
+
+ @Override
+ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests) throws Exception {
+ Connection conn = null;
+ Map valueMap = new HashMap();
+
+ try{
+ conn = getConnection();
+ if (!conn.isValid()) {
+ return;
+ }
+ for (MeasurementScheduleRequest request : requests) {
+ String name = request.getName();
+ LOG.info("Measurement name = " + name); //$NON-NLS-1$
+
+ Object metricReturnObject = conn.getMetric(getComponentType(), this.getComponentIdentifier(), name, valueMap);
+
+ try {
+ if (request.getName().equals(ComponentType.Metric.HIGH_WATER_MARK)) {
+ report.addData(new MeasurementDataNumeric(request,
+ (Double)metricReturnObject));
+ }
+ } catch (Exception e) {
+ LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
+ + "]. Cause: " + e); //$NON-NLS-1$
+ throw(e);
+ }
+ }
+ }finally{
+ conn.close();
+ }
+
+ }
+
+
+ /**
+ * The plugin container will call this method and it needs to obtain the
+ * current configuration of the managed resource. Your plugin will obtain
+ * the managed resource's configuration in your own custom way and populate
+ * the returned Configuration object with the managed resource's
+ * configuration property values.
+ *
+ * @see ConfigurationFacet#loadResourceConfiguration()
+ *
+ */
+ @Override
+ public Configuration loadResourceConfiguration() {
+ // here we simulate the loading of the managed resource's configuration
+ Configuration config = this.getResourceConfiguration() ;
+ if (config == null) {
+ // for this example, we will create a simple dummy configuration to
+ // start with.
+ // note that it is empty, so we're assuming there are no required
+ // configs in the plugin descriptor.
+ config = new Configuration();
+ }
+
+ Properties props;
+ try {
+ props = getConnection().getProperties(this.getComponentType(), this.getComponentIdentifier());
+ } catch (ConnectionException e) {
+ LOG.error("Failed to obtain process properties for [" + this.getComponentIdentifier() //$NON-NLS-1$
+ + "]. Cause: " + e); //$NON-NLS-1$
+ throw new InvalidPluginConfigurationException(e);
+ }
+
+ if (props != null && props.size() > 0) {
+ Iterator it=props.keySet().iterator();
+ while(it.hasNext()) {
+ String k = (String)it.next();
+
+ config.put(new PropertySimple(k, props.get(k)));
+
+ }
+
+ }
+
+
+ this.setResourceConfiguration(config);
+ return this.getResourceConfiguration();
+ }
+
+
+ protected static String deriveFileName(final String identifier) {
+
+ String startFileName = identifier.substring(0, identifier.indexOf("|")); //$NON-NLS-1$
+ String endFileName = identifier.substring(identifier.indexOf("|")+1, identifier.length()); //$NON-NLS-1$
+
+ startFileName = replaceAll(startFileName, ".", "_"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String logfilename = startFileName.toLowerCase() + "_" + endFileName + ".log"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ return logfilename;
+
+ }
+
+ private void startEventPollers() {
+ Configuration pluginConfig = resourceContext.getPluginConfiguration();
+ Boolean enabled = Boolean.valueOf(pluginConfig.getSimpleValue(
+ PLUGIN_CONFIG_PROP_ERROR_LOG_EVENTS_ENABLED, null)); //$NON-NLS-1$
+ if (enabled) {
+
+ String installdir = pluginConfig.getSimpleValue(
+ INSTALL_DIR, null); //$NON-NLS-1$
+ if (installdir == null) {
+ throw new InvalidPluginConfigurationException(
+ "Installation directory could not be determined in order for the process to monitor the log files"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
+ String logFileName = deriveFileName(this.getComponentIdentifier());
+
+ String relativelogname = pluginConfig.getSimpleValue(
+ PLUGIN_CONFIG_PROP_ERROR_LOG_FILE_PATH,
+ "/log/" + logFileName); //$NON-NLS-1$
+
+ errorLogFile = new File(installdir + "/" + relativelogname); //$NON-NLS-1$
+
+ LOG.info("Start event polling on logfile: " + errorLogFile.getAbsolutePath()); //$NON-NLS-1$
+
+ JBEDSPErrorLogEntryProcessor processor = new JBEDSPErrorLogEntryProcessor(
+ ERROR_LOG_ENTRY_EVENT_TYPE, errorLogFile);
+ String includesPatternString = pluginConfig.getSimpleValue(
+ PLUGIN_CONFIG_PROP_ERROR_LOG_INCLUDES_PATTERN, null);
+ if (includesPatternString != null) {
+ try {
+ Pattern includesPattern = Pattern
+ .compile(includesPatternString);
+ processor.setIncludesPattern(includesPattern);
+ } catch (PatternSyntaxException e) {
+ throw new InvalidPluginConfigurationException(
+ "Includes pattern [" + includesPatternString + "] is not a valid regular expression."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ String minimumSeverityString = pluginConfig.getSimpleValue(
+ PLUGIN_CONFIG_PROP_ERROR_LOG_MINIMUM_SEVERITY, null);
+ if (minimumSeverityString != null) {
+ EventSeverity minimumSeverity = EventSeverity
+ .valueOf(minimumSeverityString.toUpperCase());
+ processor.setMinimumSeverity(minimumSeverity);
+ }
+ EventPoller poller = new LogFileEventPoller(this.eventContext,
+ ERROR_LOG_ENTRY_EVENT_TYPE, errorLogFile, processor);
+ this.eventContext.registerEventPoller(poller, 30, errorLogFile
+ .getPath());
+ }
+ }
+
+ private void stopEventPollers() {
+// Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
+// File errorLogFile =
+// resolvePathRelativeToServerRoot(pluginConfig.getSimpleValue(PLUGIN_CONFIG_PROP_ERROR_LOG_FILE_PATH,
+// DEFAULT_ERROR_LOG_PATH));
+ this.eventContext.unregisterEventPoller(ERROR_LOG_ENTRY_EVENT_TYPE, errorLogFile.getPath());
+ }
+
+
+ /*
+ * Replace all occurrences of the search string with the replace string
+ * in the source string. If any of the strings is null or the search string
+ * is zero length, the source string is returned.
+ * @param source the source string whose contents will be altered
+ * @param search the string to search for in source
+ * @param replace the string to substitute for search if present
+ * @return source string with *all* occurrences of the search string
+ * replaced with the replace string
+ */
+ private static String replaceAll(String source, String search, String replace) {
+ if (source != null && search != null && search.length() > 0 && replace != null) {
+ int start = source.indexOf(search);
+ if (start > -1) {
+ StringBuffer newString = new StringBuffer(source);
+ replaceAll(newString, search, replace);
+ return newString.toString();
+ }
+ }
+ return source;
+ }
+
+ private static void replaceAll(StringBuffer source, String search, String replace) {
+ if (source != null && search != null && search.length() > 0 && replace != null) {
+ int start = source.toString().indexOf(search);
+ while (start > -1) {
+ int end = start + search.length();
+ source.replace(start, end, replace);
+ start = source.toString().indexOf(search, start + replace.length());
+ }
+ }
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessDiscoveryComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessDiscoveryComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.Collection;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.VMComponent;
+
+
+
+/**
+ *
+ * The discovery component class for the MetaMatrix server node
+ *
+ */
+public class ProcessDiscoveryComponent extends NodeChildrenDiscoveryComponent {
+
+
+ Collection<Component> getComponents(Connection conn, Facet parent) throws ConnectionException {
+ return conn.discoverComponents(ConnectionConstants.ComponentType.Runtime.Process.TYPE, parent.getComponentIdentifier());
+ }
+
+ protected void addAdditionalProperties(Configuration configuration, Component component) throws InvalidPluginConfigurationException {
+ configuration.put(new PropertySimple(VMComponent.PORT, ((VMComponent)component).getPort()));
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/ProcessDiscoveryComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries.Query;
+import org.teiid.rhq.plugin.objects.ExecutedResourceConfigurationResultImpl;
+
+
+/**
+ * MetaMatrix Connector component class
+ *
+ */
+public class QueriesComponent extends Facet {
+
+ private final Log LOG = LogFactory.getLog(QueriesComponent.class);
+
+
+ private ExecutedResourceConfigurationResultImpl getQueries = null;
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 1.0
+ */
+ @Override
+ String getComponentType() {
+ return Queries.TYPE;
+ }
+
+ public void start(ResourceContext context) {
+ super.start(context);
+
+ Map defns = context.getResourceType().getResourceConfigurationDefinition().getPropertyDefinitions();
+
+ getQueries = new ExecutedResourceConfigurationResultImpl(
+ this.getComponentType(),
+ Query.GET_QUERIES,
+ defns);
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map argumentMap) {
+
+
+ }
+
+ @Override
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+
+ }
+
+ @Override
+ public void getValues(MeasurementReport arg0,
+ Set<MeasurementScheduleRequest> arg1) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ /**
+ * The plugin container will call this method and it needs to obtain the
+ * current configuration of the managed resource. Your plugin will obtain
+ * the managed resource's configuration in your own custom way and populate
+ * the returned Configuration object with the managed resource's
+ * configuration property values.
+ *
+ * @see ConfigurationFacet#loadResourceConfiguration()
+ *
+ */
+ @Override
+ public Configuration loadResourceConfiguration() {
+ // here we simulate the loading of the managed resource's configuration
+ Configuration config = this.getResourceConfiguration() ;
+ if (config == null) {
+ // for this example, we will create a simple dummy configuration to
+ // start with.
+ // note that it is empty, so we're assuming there are no required
+ // configs in the plugin descriptor.
+ config = new Configuration();
+
+
+ }
+
+ getQueries.reset();
+
+ execute(getQueries, new HashMap());
+
+
+ config.put( (PropertyList) getQueries.getResult());
+
+
+ this.setResourceConfiguration(config);
+ return this.getResourceConfiguration();
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/SecurityComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/SecurityComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/SecurityComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session.Query;
+import org.teiid.rhq.plugin.objects.ExecutedResourceConfigurationResultImpl;
+
+
+/**
+ * MetaMatrix Connector component class
+ *
+ */
+public class SecurityComponent extends Facet {
+
+ private final Log LOG = LogFactory.getLog(SecurityComponent.class);
+
+
+ private ExecutedResourceConfigurationResultImpl getSessions = null;
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 1.0
+ */
+ @Override
+ String getComponentType() {
+ return Session.TYPE;
+ }
+
+ public void start(ResourceContext context) {
+ super.start(context);
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map argumentMap) {
+
+
+ }
+
+ @Override
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+
+ }
+
+ @Override
+ public void getValues(MeasurementReport arg0,
+ Set<MeasurementScheduleRequest> arg1) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ /**
+ * The plugin container will call this method and it needs to obtain the
+ * current configuration of the managed resource. Your plugin will obtain
+ * the managed resource's configuration in your own custom way and populate
+ * the returned Configuration object with the managed resource's
+ * configuration property values.
+ *
+ * @see ConfigurationFacet#loadResourceConfiguration()
+ *
+ */
+ @Override
+ public Configuration loadResourceConfiguration() {
+
+ return super.loadResourceConfiguration();
+ }
+
+
+// class SessionComparable implements Comparator {
+//
+// public int compare(Object arg0, Object arg1) {
+// // TODO Auto-generated method stub
+// Component a = (Component) arg0;
+// Component b = (Component) arg1;
+//
+// if ( a == null && b == null ) {
+// return 0;
+// }
+// if ( a != null && b == null ) {
+// return 1;
+// }
+// if ( a == null && b != null ) {
+// return -1;
+// }
+// int result = a.get.compareTo(b.getDisplayName());
+// return result;
+// }
+
+
+
+ // }
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/SecurityComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session.Query;
+import org.teiid.rhq.plugin.objects.ExecutedResourceConfigurationResultImpl;
+
+
+/**
+ * MetaMatrix Connector component class
+ *
+ */
+public class SessionComponent extends Facet {
+
+ private final Log LOG = LogFactory.getLog(SessionComponent.class);
+
+
+ private ExecutedResourceConfigurationResultImpl getSessions = null;
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 1.0
+ */
+ @Override
+ String getComponentType() {
+ return Session.TYPE;
+ }
+
+ public void start(ResourceContext context) {
+ super.start(context);
+
+ Map defns = context.getResourceType().getResourceConfigurationDefinition().getPropertyDefinitions();
+
+ getSessions = new ExecutedResourceConfigurationResultImpl(
+ this.getComponentType(),
+ Query.GET_SESSIONS,
+ defns);
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map argumentMap) {
+
+
+ }
+
+ @Override
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+
+ }
+
+ @Override
+ public void getValues(MeasurementReport arg0,
+ Set<MeasurementScheduleRequest> arg1) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ /**
+ * The plugin container will call this method and it needs to obtain the
+ * current configuration of the managed resource. Your plugin will obtain
+ * the managed resource's configuration in your own custom way and populate
+ * the returned Configuration object with the managed resource's
+ * configuration property values.
+ *
+ * @see ConfigurationFacet#loadResourceConfiguration()
+ *
+ */
+ @Override
+ public Configuration loadResourceConfiguration() {
+ // here we simulate the loading of the managed resource's configuration
+ Configuration config = this.getResourceConfiguration() ;
+ if (config == null) {
+ // for this example, we will create a simple dummy configuration to
+ // start with.
+ // note that it is empty, so we're assuming there are no required
+ // configs in the plugin descriptor.
+ config = new Configuration();
+
+
+ }
+
+ getSessions.reset();
+
+ execute(getSessions, new HashMap());
+
+
+ config.put( (PropertyList) getSessions.getResult());
+
+
+ this.setResourceConfiguration(config);
+ return this.getResourceConfiguration();
+ }
+
+
+// class SessionComparable implements Comparator {
+//
+// public int compare(Object arg0, Object arg1) {
+// // TODO Auto-generated method stub
+// Component a = (Component) arg0;
+// Component b = (Component) arg1;
+//
+// if ( a == null && b == null ) {
+// return 0;
+// }
+// if ( a != null && b == null ) {
+// return 1;
+// }
+// if ( a == null && b != null ) {
+// return -1;
+// }
+// int result = a.get.compareTo(b.getDisplayName());
+// return result;
+// }
+
+
+
+ // }
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/SystemComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/SystemComponent.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/SystemComponent.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.MeasurementDataNumeric;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries.Query;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.System.Metrics;
+import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.System.Operations;
+
+
+/**
+ *
+ */
+public class SystemComponent extends Facet {
+ private final Log LOG = LogFactory.getLog(SystemComponent.class);
+
+ /**
+ * Property is used to identify an unreachable system
+ */
+ protected static final String UNREACHABLE_NAME = "UNREACHABLE_SYSTEM"; //$NON-NLS-1$
+
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 4.3
+ */
+ @Override
+ String getComponentType() {
+ return ConnectionConstants.ComponentType.Runtime.System.TYPE;
+ }
+
+ protected void setOperationArguments(String name, Configuration configuration,
+ Map valueMap) {
+
+ // Parameter logic for System Operations
+ if (name.equals(Query.GET_QUERIES) ||
+ name.equals(Operations.GET_LONGRUNNINGQUERIES)) {
+ Boolean includeSourceQueries = configuration.getSimple(ConnectionConstants.ComponentType.Operation.Value.INCLUDE_SOURCE_QUERIES).getBooleanValue();
+ Integer long_running_value = getResourceConfiguration().getSimple(ConnectionConstants.ComponentType.Operation.Value.LONG_RUNNING_QUERY_LIMIT).getIntegerValue();
+ valueMap.put(ConnectionConstants.ComponentType.Operation.Value.INCLUDE_SOURCE_QUERIES, includeSourceQueries);
+ valueMap.put(ConnectionConstants.ComponentType.Operation.Value.LONG_RUNNING_QUERY_LIMIT, long_running_value);
+ }else if (name.equals(Operations.BOUNCE_SYSTEM)) {
+ Boolean waitUntilFinished = configuration.getSimple(ConnectionConstants.ComponentType.Operation.Value.WAIT_UNTIL_FINISHED).getBooleanValue();
+ valueMap.put(ConnectionConstants.ComponentType.Operation.Value.WAIT_UNTIL_FINISHED, waitUntilFinished);
+ }else if (name.equals(ConnectionConstants.ComponentType.Operation.KILL_REQUEST)) {
+ String key = ConnectionConstants.ComponentType.Operation.Value.REQUEST_ID;
+ valueMap.put(key, configuration.getSimple(key).getStringValue());
+ }else if (name.equals(ConnectionConstants.ComponentType.Operation.GET_PROPERTIES) ) {
+ String key = ConnectionConstants.IDENTIFIER;
+ valueMap.put(key, getComponentIdentifier());
+ }
+
+ }
+
+
+ @Override
+ public void getValues(MeasurementReport report,
+ Set<MeasurementScheduleRequest> requests) throws Exception {
+
+ // because the sytsem object will be created before the use actually connects, checks have to be
+ // made not to perform actions that will require a connection before its available
+ if (!this.isAvailable()) {
+ return;
+ }
+
+ Connection conn = null;
+ Map valueMap = new HashMap();
+
+ try {
+ conn = getConnection();
+ if (!conn.isValid()) {
+ return;
+ }
+ for (MeasurementScheduleRequest request : requests) {
+ String name = request.getName();
+ LOG.debug("Measurement name = " + name); //$NON-NLS-1$
+
+ //Initialize any parameters to be used in the retrieval of metric values
+ if (request.getName().equals(Metrics.LONG_RUNNING_QUERIES)) {
+ Integer value = getResourceConfiguration().getSimple(ConnectionConstants.ComponentType.Operation.Value.LONG_RUNNING_QUERY_LIMIT).getIntegerValue();
+ valueMap.put(ComponentType.Operation.Value.LONG_RUNNING_QUERY_LIMIT, value);
+ }
+
+ Object metricReturnObject = conn.getMetric(getComponentType(),
+ this.getComponentIdentifier(),
+ name,
+ valueMap);
+
+ try {
+ if (request.getName().equals(
+ Metrics.QUERY_COUNT)) {
+ report.addData(new MeasurementDataNumeric(request,
+ (Double) metricReturnObject));
+ } else {
+ if (request.getName().equals(
+ Metrics.SESSION_COUNT)) {
+ report.addData(new MeasurementDataNumeric(request,
+ (Double) metricReturnObject));
+ } else {
+ if (request.getName().equals(
+ Metrics.LONG_RUNNING_QUERIES)) {
+ report.addData(new MeasurementDataNumeric(
+ request, (Double) metricReturnObject));
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ LOG.error("Failed to obtain measurement [" + name //$NON-NLS-1$
+ + "]. Cause: " + e); //$NON-NLS-1$
+ // throw(e);
+ }
+ }
+ } finally {
+ if (conn != null) {
+ conn.close();
+ }
+ }
+ }
+
+//
+// @Override
+// public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+//
+// Properties props = System.getProperties();
+//
+// Iterator<PropertySimple> pluginPropIter = report.getConfiguration().getSimpleProperties().values().iterator();
+//
+// while (pluginPropIter.hasNext()){
+// PropertySimple pluginProp = pluginPropIter.next();
+// props.put(pluginProp.getName(), pluginProp.getStringValue());
+// }
+//
+// SingletonConnectionManager.getInstance().initialize(props);
+// super.updateResourceConfiguration(report);
+//
+// }
+
+}
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/SystemComponent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/log/JBEDSPErrorLogEntryProcessor.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/log/JBEDSPErrorLogEntryProcessor.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/log/JBEDSPErrorLogEntryProcessor.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.log;
+
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.rhq.core.domain.event.EventSeverity;
+import org.rhq.core.pluginapi.event.log.MultiLineLogEntryProcessor;
+
+
+/**
+ * @since 4.3
+ */
+public class JBEDSPErrorLogEntryProcessor extends MultiLineLogEntryProcessor {
+
+
+ /**
+ * The regex for the primary log line: '['date']' '['severityLevel']' '['clientIP']' message
+ * e.g.: [Wed Oct 11 14:32:52 2008] [error] [client 127.0.0.1] client denied by server configuration
+ * NOTE: The message portion may contain multiple lines.
+ */
+ private static final String REGEX = "(.*) (.*) (INFO|WARNING|ERROR|DEBUG) (.*)"; //$NON-NLS-1$
+ private static final Pattern PATTERN = Pattern.compile(REGEX);
+
+ private static final String DATE_PATTERN = "MMM dd, yyyy kk:mm:ss.SSS"; // e.g.: Aug 26, 2008 13:10:11.371 //$NON-NLS-1$
+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat(DATE_PATTERN);
+
+ private static final Map<SeverityLevel, EventSeverity> LEVEL_TO_SEVERITY_MAP = new LinkedHashMap();
+ static {
+ LEVEL_TO_SEVERITY_MAP.put(SeverityLevel.DEBUG, EventSeverity.DEBUG);
+ LEVEL_TO_SEVERITY_MAP.put(SeverityLevel.INFO, EventSeverity.INFO);
+ LEVEL_TO_SEVERITY_MAP.put(SeverityLevel.WARNING, EventSeverity.WARN);
+ LEVEL_TO_SEVERITY_MAP.put(SeverityLevel.ERROR, EventSeverity.ERROR);
+ }
+
+ public JBEDSPErrorLogEntryProcessor(String eventType, File logFile) {
+ super(eventType, logFile);
+ }
+
+ protected Pattern getPattern() {
+ return PATTERN;
+ }
+
+ protected DateFormat getDefaultDateFormat() {
+ return DATE_FORMAT;
+ }
+
+ protected LogEntry processPrimaryLine(Matcher matcher) throws ParseException {
+ String dateString = matcher.group(1);
+ Date timestamp = parseDateString(dateString);
+ String severityLevelString = matcher.group(3);
+ SeverityLevel severityLevel;
+ try {
+ severityLevel = SeverityLevel.valueOf(severityLevelString.toUpperCase());
+ }
+ catch (IllegalArgumentException e) {
+ throw new ParseException("Unknown severity level: " + severityLevelString); //$NON-NLS-1$
+ }
+ EventSeverity severity = LEVEL_TO_SEVERITY_MAP.get(severityLevel);
+ String detail = matcher.group(4);
+ return new LogEntry(timestamp, severity, detail);
+ }
+
+ private enum SeverityLevel {
+ DEBUG,
+ INFO,
+ WARNING,
+ ERROR
+ }
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/log/JBEDSPErrorLogEntryProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ConfigurationResultImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ConfigurationResultImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ConfigurationResultImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.objects;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+
+
+public class ConfigurationResultImpl {
+
+
+ public static Collection mapProperties(ResourceDiscoveryContext discoveryContext, Properties values ) {
+ Set<PropertySimple> properties = new HashSet();
+ if (discoveryContext.getResourceType().getPluginConfigurationDefinition() == null) {
+ return Collections.EMPTY_LIST;
+ }
+ Map<String , PropertyDefinition> propDefs = discoveryContext.getResourceType().getPluginConfigurationDefinition().getPropertyDefinitions();
+
+ Iterator<String> propkeys = propDefs.keySet().iterator();
+
+ while (propkeys.hasNext()) {
+ final String key = propkeys.next();
+ PropertyDefinition pdef = propDefs.get(key);
+
+ if (pdef instanceof PropertyDefinitionSimple) {
+ String fieldName = ((PropertyDefinitionSimple) pdef).getName();
+ if (values.containsKey(fieldName)) {
+
+ properties.add(new PropertySimple(key, values.get(fieldName)));
+ }
+ } else if (pdef instanceof PropertyDefinitionList) {
+ PropertyDefinition propertyDefinitionMap = ((PropertyDefinitionList) pdef)
+ .getMemberDefinition();
+ Map simpleProperties = ((PropertyDefinitionMap) propertyDefinitionMap)
+ .getPropertyDefinitions();
+ Iterator simplePropertiesIter = simpleProperties.values()
+ .iterator();
+
+ while (simplePropertiesIter.hasNext()) {
+ PropertyDefinition simpleProp = (PropertyDefinition) simplePropertiesIter
+ .next();
+ String fieldName = ((PropertyDefinitionSimple) simpleProp)
+ .getName();
+ if (values.contains(fieldName)) {
+
+ properties.add(new PropertySimple(key, values.get(fieldName)));
+ }
+ }
+
+ }
+
+ }
+
+ return properties;
+
+ }
+
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ConfigurationResultImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedOperationResultImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedOperationResultImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedOperationResultImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.objects;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.domain.operation.OperationDefinition;
+import org.rhq.core.pluginapi.operation.OperationResult;
+import org.teiid.rhq.comm.ExecutedResult;
+
+
+public class ExecutedOperationResultImpl implements ExecutedResult {
+
+ Set operationDefinitionSet;
+
+ String operationName;
+
+ String componentType;
+
+ final static String LISTNAME = "list"; //$NON-NLS-1$
+
+ final static String MAPNAME = "map"; //$NON-NLS-1$
+
+// String mapName;
+
+ Object result;
+
+ Object content;
+
+ List fieldNameList;
+
+ OperationResult operationResult = new OperationResult();
+
+ public ExecutedOperationResultImpl() {
+ }
+
+ public ExecutedOperationResultImpl(String componentType, String operationName, Set operationDefinitionSet) {
+ this.componentType = componentType;
+ this.operationName = operationName;
+ this.operationDefinitionSet = operationDefinitionSet;
+ init();
+ }
+
+ public String getComponentType() {
+ return this.componentType;
+ }
+
+ public String getOperationName() {
+ return this.operationName;
+ }
+
+ public OperationResult getOperationResult() {
+ return operationResult;
+ }
+
+ public List getFieldNameList() {
+ return fieldNameList;
+ }
+
+ public Object getResult() {
+ return result;
+ }
+
+ private void setComplexResult() {
+ PropertyList list = new PropertyList(LISTNAME); //$NON-NLS-1$
+ PropertyMap pm;
+ Iterator resultIter = ((List)content).iterator();
+ while (resultIter.hasNext()) {
+ Map reportRowMap = (Map) resultIter.next();
+ Iterator reportRowKeySetIter = reportRowMap.keySet().iterator();
+ pm = new PropertyMap("userMap"); //$NON-NLS-1$
+
+ while (reportRowKeySetIter.hasNext()) {
+ String key = (String) reportRowKeySetIter.next();
+ pm.put(new PropertySimple(key, reportRowMap.get(key)==null?"":reportRowMap.get(key))); //$NON-NLS-1$
+ }
+ list.add(pm);
+ }
+ result = list;
+ operationResult.getComplexResults().put(list);
+ }
+
+ public void setContent(List content) {
+ this.content = content;
+ setComplexResult();
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ this.result = content;
+ operationResult.setSimpleResult(content);
+ }
+
+ private void init() {
+ fieldNameList = new LinkedList();
+
+ Iterator operationsIter = operationDefinitionSet.iterator();
+
+ while (operationsIter.hasNext()) {
+ OperationDefinition opDef = (OperationDefinition) operationsIter
+ .next();
+ if (opDef.getName().equals(operationName)) {
+ Map propDefs = opDef.getResultsConfigurationDefinition()
+ .getPropertyDefinitions();
+ PropertyDefinition listPropDefinition = (PropertyDefinition) propDefs
+ .get(LISTNAME);
+
+ PropertyDefinition propertyDefinitionMap = ((PropertyDefinitionList) listPropDefinition)
+ .getMemberDefinition();
+ Map simpleProperties = ((PropertyDefinitionMap) propertyDefinitionMap)
+ .getPropertyDefinitions();
+ Iterator simplePropertiesIter = simpleProperties.values()
+ .iterator();
+
+ while (simplePropertiesIter.hasNext()) {
+ PropertyDefinition simpleProp = (PropertyDefinition) simplePropertiesIter
+ .next();
+ String fieldName = ((PropertyDefinitionSimple) simpleProp)
+ .getName();
+ fieldNameList.add(fieldName);
+ }
+
+ break;
+ }
+ }
+ }
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedOperationResultImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedResourceConfigurationResultImpl.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedResourceConfigurationResultImpl.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedResourceConfigurationResultImpl.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.objects;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.domain.operation.OperationDefinition;
+import org.rhq.core.pluginapi.operation.OperationResult;
+import org.teiid.rhq.comm.ExecutedResult;
+
+
+public class ExecutedResourceConfigurationResultImpl implements ExecutedResult {
+
+ Map propertDefinitions;
+
+ String operationName;
+
+ String componentType;
+
+ final static String LISTNAME = "list"; //$NON-NLS-1$
+
+ final static String MAPNAME = "map"; //$NON-NLS-1$
+
+ Object result;
+
+ Object content;
+
+ List fieldNameList;
+
+
+ public ExecutedResourceConfigurationResultImpl(String componentType, String operationName, Map propDefs) {
+ this.componentType = componentType;
+ this.operationName = operationName;
+ this.propertDefinitions = propDefs;
+ init();
+ }
+
+ public void reset() {
+ result = null;
+ content = null;
+ }
+
+ public String getComponentType() {
+ return this.componentType;
+ }
+
+ public String getOperationName() {
+ return this.operationName;
+ }
+
+
+
+ public List getFieldNameList() {
+ return fieldNameList;
+ }
+
+ public Object getResult() {
+ return result;
+ }
+
+ private void setComplexResult() {
+ PropertyList list = new PropertyList(LISTNAME); //$NON-NLS-1$
+ PropertyMap pm;
+ Iterator resultIter = ((List)content).iterator();
+ while (resultIter.hasNext()) {
+ Map reportRowMap = (Map) resultIter.next();
+ Iterator reportRowKeySetIter = reportRowMap.keySet().iterator();
+ pm = new PropertyMap("userMap"); //$NON-NLS-1$
+
+ while (reportRowKeySetIter.hasNext()) {
+ String key = (String) reportRowKeySetIter.next();
+ pm.put(new PropertySimple(key, reportRowMap.get(key)==null?"":reportRowMap.get(key))); //$NON-NLS-1$
+ }
+ list.add(pm);
+ }
+
+ result = list;
+ }
+
+
+ public void setContent(List content) {
+ this.content = content;
+ setComplexResult();
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ private void init() {
+ fieldNameList = new LinkedList();
+
+ PropertyDefinition listPropDefinition = (PropertyDefinition) propertDefinitions
+ .get(LISTNAME);
+
+ PropertyDefinition propertyDefinitionMap = ((PropertyDefinitionList) listPropDefinition)
+ .getMemberDefinition();
+ Map simpleProperties = ((PropertyDefinitionMap) propertyDefinitionMap)
+ .getPropertyDefinitions();
+ Iterator simplePropertiesIter = simpleProperties.values()
+ .iterator();
+
+ while (simplePropertiesIter.hasNext()) {
+ PropertyDefinition simpleProp = (PropertyDefinition) simplePropertiesIter
+ .next();
+ String fieldName = ((PropertyDefinitionSimple) simpleProp)
+ .getName();
+ fieldNameList.add(fieldName);
+ }
+
+
+ }
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/objects/ExecutedResourceConfigurationResultImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginUtils.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginUtils.java (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginUtils.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.util;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertySimple;
+
+public class PluginUtils {
+
+ /*
+ * Returns a Collection of PropertySimple instances from a Properties instance
+ */
+ public static Collection<Property> getSimplePropertyCollection(Properties properties){
+ Collection<Property> collection = Collections.emptyList();
+
+ for (String key : properties.stringPropertyNames()) {
+ collection.add(new PropertySimple(key,properties.get(key)));
+ }
+
+ return collection;
+ }
+}
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/util/configuration.properties
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/util/configuration.properties (rev 0)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/util/configuration.properties 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,3 @@
+url=mm://localhost:31000
+username=Admin
+password=mm
\ No newline at end of file
Property changes on: trunk/console/src/main/java/org/teiid/rhq/plugin/util/configuration.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/resources/embedded/META-INF/rhq-plugin.xml
===================================================================
--- trunk/console/src/resources/embedded/META-INF/rhq-plugin.xml (rev 0)
+++ trunk/console/src/resources/embedded/META-INF/rhq-plugin.xml 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,635 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */-->
+
+<plugin name="TeiidPlugin" displayName="Teiid Plugin"
+ package="org.teiid.rhq.plugin" version="2.0.0"
+ description="Supports management and monitoring of JBoss Teiid DataServices version 6.2"
+
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <server name="Teiid Data Services"
+ discovery="PlatformDiscoveryComponent"
+ class="PlatformComponent"
+ description="JBoss Teiid DataServices"
+ supportsManualAdd="true"
+ singleton="true">
+
+
+ <subcategories>
+ <subcategory name="Runtime"/>
+ <subcategory name="Resources"/>
+ </subcategories>
+
+ <resource-configuration>
+ <c:group name="connection" displayName="Connection Info">
+ <c:description>Connection</c:description>
+ <c:simple-property name="url" displayName="Teiid URL"
+ description="The URL with which to connect to the Teiid Data Service instance (e.g. mm://localhost:31000)."
+ default="mm://localhost:31000"/>
+ <c:simple-property name="username" required="true" description="The name of the administrative principal (i.e. user) to authenticate."/>
+ <c:simple-property name="password" type="password" required="true"
+ description="The credentials (i.e. password) that should be used to authenticate the administrative principal."/>
+ </c:group>
+ </resource-configuration>
+
+
+ <server name="Sessions"
+ subCategory="Runtime"
+ discovery="NodeDiscoveryComponent"
+ description="Active / Inactive sessions connected to the Teidd Server"
+ class="SessionComponent"
+ singleton="true">
+
+<!--
+ group name = operation name or query name
+
+ simple-property name = the method name on the object to get the value
+-->
+ <resource-configuration>
+ <c:group name="getSessions" displayName="Sessions">
+
+ <c:list-property name="list"
+ displayName="Current Sessions"
+ description="Sessions currently connected to the Teiid"
+ required="false">
+ <c:map-property name="map">
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string" readOnly="true"
+ description="The id for this session" />
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string" readOnly="true"
+ description="The username for the user of this session" />
+ <c:simple-property
+ displayName="Application Name" name="getApplicationName"
+ type="string" readOnly="true"
+ description="The name of the application this user is accessing Teiid through" />
+ <c:simple-property displayName="VDB Name"
+ name="getVDBName" type="string" readOnly="true"
+ description="The name of the VDB the user is connected to" />
+ <c:simple-property displayName="VDB Version"
+ name="getVDBVersion" type="string" readOnly="true"
+ description="The version of the VDB the user is connected to" />
+
+ <c:simple-property displayName="State"
+ name="getStateAsString" type="string" readOnly="true"
+ description="The current state of this session" />
+
+ <c:simple-property displayName="IP Address"
+ name="getIPAddress" type="string" readOnly="true"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Host Name"
+ name="getHostName" type="string" readOnly="true"
+ description="The host machine from which this user connected" />
+ </c:map-property>
+ </c:list-property>
+
+ </c:group>
+ </resource-configuration>
+
+ </server>
+
+ <server name="Queries"
+ subCategory="Runtime"
+ discovery="NodeDiscoveryComponent"
+ description="Current queries executing against the Teiid Server"
+ class="QueriesComponent"
+ singleton="true">
+
+<!--
+ group name = operation name or query name
+
+ simple-property name = the method name on the object to get the value
+-->
+ <resource-configuration>
+ <c:group name="listQueries" displayName="Executing Queries">
+
+ <c:list-property name="list"
+ displayName="Executing Queries"
+ description="Current queries executing in the Teiid system"
+ required="false">
+ <c:map-property name="map">
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string"
+ description="The username for the user that submitted this query" />
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string"
+ description="The id for the session" />
+ <c:simple-property displayName="Request ID"
+ name="getRequestID" type="string"
+ description="The id for the request" />
+ <c:simple-property displayName="Start Time"
+ name="getCreated" type="string"
+ description="The time this query has been running" />
+ <c:simple-property displayName="Transaction ID"
+ name="getTransactionID" type="string"
+ description="The version of the VDB the user is connected to" />
+ <c:simple-property displayName="SQL String"
+ name="getSqlCommand" type="string"
+ description="The SQL string for this query" />
+ <c:simple-property
+ displayName="Connector Binding Name"
+ name="getConnectorBindingName" type="string"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Node ID"
+ name="getNodeID" type="string"
+ description="The node ID of this query" />
+ <c:simple-property displayName="Source Request"
+ name="isSource" type="string"
+ description="If false this is the top level query. If true this a physical source query." />
+ </c:map-property>
+ </c:list-property>
+
+ </c:group>
+ </resource-configuration>
+
+ </server>
+
+
+
+
+
+ <server name="System"
+ subCategory="Runtime"
+ discovery="NodeDiscoveryComponent"
+ class="SystemComponent"
+ description="Operational System"
+ supportsManualAdd="true"
+ singleton="true">
+
+
+ <operation name="bounceSystem"
+ displayName="Bounce System"
+ description="Stop and restart the system">
+ <parameters>
+ <c:simple-property name="waitUntilFinished"
+ type="boolean" default="false"
+ description="If true, this method waits until the operation is finished before returning. This may take a long time to complete. If false, this method returns immediately, even though the operation may not be finished." />
+ </parameters>
+ </operation>
+<!--
+ <operation name="listUsers"
+ displayName="View current user sessions"
+ description="List current user sessions connected to this Teiid System">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string"
+ description="The username for the user of this session" />
+ <c:simple-property
+ displayName="Application Name" name="getApplicationName"
+ type="string"
+ description="The name of the application this user is accessing Teiid through" />
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string"
+ description="The id for this session" />
+ <c:simple-property displayName="VDB Name"
+ name="getVDBName" type="string"
+ description="The name of the VDB the user is connected to" />
+ <c:simple-property displayName="VDB Version"
+ name="getVDBVersion" type="string"
+ description="The version of the VDB the user is connected to" />
+ <c:simple-property displayName="Product Name"
+ name="getProductName" type="string"
+ description="The product name" />
+ <c:simple-property displayName="IP Address"
+ name="getIPAddress" type="string"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Host Name"
+ name="getHostName" type="string"
+ description="The host name for this user's connection" />
+ <c:simple-property displayName="Last Ping Time"
+ name="getLastPingTime" type="string"
+ description="The last time this client was ping'd" />
+ <c:simple-property displayName="State"
+ name="getStateAsString" type="string"
+ description="The current state of this session" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+-->
+
+<!--
+ <operation name="listQueries" displayName="View current queries"
+ description="List current queries executing against the Teiid System">
+ <parameters>
+ <c:simple-property name="includeSourceQueries"
+ type="boolean" default="true"
+ description="If true, source queries will be included in the results. If false, only top-level queries will be included in the results." />
+ </parameters>
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string"
+ description="The username for the user that submitted this query" />
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string"
+ description="The id for the session" />
+ <c:simple-property displayName="Request ID"
+ name="getRequestID" type="string"
+ description="The id for the request" />
+ <c:simple-property displayName="Start Time"
+ name="getCreated" type="string"
+ description="The time this query has been running" />
+ <c:simple-property displayName="Transaction ID"
+ name="getTransactionID" type="string"
+ description="The version of the VDB the user is connected to" />
+ <c:simple-property displayName="SQL String"
+ name="getSqlCommand" type="string"
+ description="The SQL string for this query" />
+ <c:simple-property
+ displayName="Connector Binding Name"
+ name="getConnectorBindingName" type="string"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Node ID"
+ name="getNodeID" type="string"
+ description="The node ID of this query" />
+ <c:simple-property displayName="Source Request"
+ name="isSource" type="string"
+ description="If false this is the top level query. If true this a physical source query." />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+-->
+ <operation name="listLongRunningQueries"
+ displayName="View current long running queries"
+ description="List current queries executing against the Teiid System that have surpassed the long running query threshhold">
+ <parameters>
+ <c:simple-property name="includeSourceQueries"
+ type="boolean" default="true"
+ description="If true, source queries will be included in the results. If false, only top-level queries will be included in the results." />
+ </parameters>
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string"
+ description="The username for the user that submitted this query" />
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string"
+ description="The name of the resource whose availability is being reported" />
+ <c:simple-property displayName="Request ID"
+ name="getRequestID" type="string"
+ description="The id for the request" />
+ <c:simple-property displayName="Start Time"
+ name="getCreated" type="string"
+ description="The time this query has been running" />
+ <c:simple-property displayName="Transaction ID"
+ name="getTransactionID" type="string"
+ description="The version of the VDB the user is connected to" />
+ <c:simple-property displayName="SQL String"
+ name="getSqlCommand" type="string"
+ description="The SQL string for this query" />
+ <c:simple-property
+ displayName="Connector Binding Name"
+ name="getConnectorBindingName" type="string"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Node ID"
+ name="getNodeID" type="string"
+ description="The node ID of this query" />
+ <c:simple-property displayName="Source Request"
+ name="isSource" type="string"
+ description="If false this is the top level query. If true this a physical source query." />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <operation name="killRequest" displayName="Terminate query"
+ description="Terminate the processing of a query and it's source queries">
+ <parameters>
+ <c:simple-property displayName="SessionID|RequestID"
+ name="requestID" type="string" required="true"
+ description="The IDs of the session|request to terminate (use format = sessionID|requestID)" />
+ </parameters>
+ </operation>
+
+
+ <metric displayName="Query Count" defaultOn="true"
+ displayType="summary" category="throughput" property="queryCount"
+ description="The number of queries for a given point in time" />
+
+ <metric displayName="Long Running Queries" defaultOn="true"
+ displayType="summary" category="performance"
+ property="longRunningQueries"
+ description="The number of queries that have been running longer than the limit set for queries. The default is 60 minutes, but this may be overridden by the 'longRunningQueryTime' system variable." />
+
+ <metric displayName="Session Count" defaultOn="true"
+ displayType="summary" category="throughput" property="sessionCount"
+ description="The number of user connections for a given point in time" />
+
+ <resource-configuration>
+ <c:group name="general" displayName="General" hiddenByDefault="false">
+ <c:description>Query Configuration</c:description>
+ <c:simple-property name="longRunningQueryLimit" type="integer" activationPolicy="immediate" units="seconds" default="600" displayName="Long Running Query limit" description="The value (in seconds) to use to determine if a query is to be considered 'long running'.">
+ <c:constraint>
+ <c:integer-constraint minimum="0" maximum="999999" />
+ </c:constraint>
+ </c:simple-property>
+ </c:group>
+ </resource-configuration>
+
+
+ <server name="Host"
+ discovery="HostDiscoveryComponent"
+ class="HostComponent"
+ description="Teiid Host"
+ createDeletePolicy="delete-only">
+
+ <resource-configuration>
+ <c:group name="hostinfo" displayName="Host Info">
+ <c:description>Host configuration information</c:description>
+
+ <c:simple-property name="metamatrix.installationDir" readOnly="true" required="false" displayName="Installation Directory"
+ description="The physical location of the Teiid server installation"/>
+ <c:simple-property name="metamatrix.log.dir" readOnly="true" required="false" displayName="Log Directory"
+ description="The physical location of the Host log files"/>
+ <c:simple-property name="metamatrix.data.dir" readOnly="true" required="false" displayName="Data Directory"
+ description="The physical location of the internal Teiid dynamic data"/>
+ <c:simple-property name="metamatrix.host.dir" readOnly="true" required="false" displayName="Host Directory"
+ description="The Host directory is where host specific files are located."/>
+ <c:simple-property name="metamatrix.host.bind.address" readOnly="true" required="false" displayName="Bind Address"
+ description="The bind address determines what interfaces the host machine will be bound to."/>
+ <c:simple-property name="metamatrix.host.physical.address" readOnly="true" required="false" displayName="Physical Address"
+ description="The physical address indicates what address a client application will use to connect."/>
+ </c:group>
+ </resource-configuration>
+
+
+ <service name="Process"
+ discovery="ProcessDiscoveryComponent"
+ class="ProcessComponent"
+ description="Teiid Process instance"
+ createDeletePolicy="both">
+
+ <plugin-configuration>
+ <c:group name="event" displayName="Process Log Tracking">
+ <c:simple-property name="enabled" type="boolean" summary="true" default="true" required="true"
+ description="A flag indicating whether of not this log Event source is currently
+ enabled (i.e. whether the associated log file should be tailed for
+ new entries)."/>
+ <c:simple-property name="minimumSeverity" required="true" default="ERROR"
+ description="The minimum severity of Events that should be collected for this
+ source. The default is ERROR.">
+ <c:property-options>
+ <c:option name="DEBUG" value="DEBUG"/>
+ <c:option name="INFO" value="INFO"/>
+ <c:option name="WARNING" value="WARNING"/>
+ <c:option name="ERROR" value="ERROR" default="true"/>
+ </c:property-options>
+ </c:simple-property>
+ </c:group>
+ </plugin-configuration>
+
+ <operation name="restartProcess"
+ displayName="Re-start Process"
+ description="Start/re-start this process" />
+ <operation name="stopProcess"
+ displayName="Stop Process"
+ description="Stop this process">
+ <parameters>
+ <c:simple-property name="stopNow" type="boolean"
+ default="true"
+ description="If true, stop the process forcefully. If false, wait until any pending work is completed." />
+ </parameters>
+ </operation>
+
+
+ <metric displayName="Query High Water Mark" defaultOn="true"
+ displayType="summary" category="utilization"
+ property="highWatermark"
+ description="High water mark for queries in the Socket Worker Queue" />
+
+ <event name="errorLogEntry" description="an entry in a log file"/>
+ <!-- Ted Jones - 06/19/08
+ Commenting out current threads metric until http://jira.jboss.org/jira/browse/JBEDSP-426 is resolved. -->
+ <!-- <metric displayName="Current Threads"
+ defaultOn="true"
+ displayType="summary"
+ category="utilization"
+ property="threadCount"
+ description="The number of active threads in the Socket Worker Queue"/> -->
+
+ <resource-configuration>
+ <c:group name="processinfo" displayName="Process Info">
+ <c:description>Process configuration information</c:description>
+ <c:simple-property name="vm.enabled" type="boolean" displayName="Start Enabled Flag"
+ description="The enabled flag allows for disabling the VM from starting without have to remove it from deployment."/>
+ <c:simple-property name="vm.socketPort" type="integer" displayName="Socket Port"
+ description="The port number for the process when socket communications are being used"/>
+
+ <c:simple-property name="vm.starter.cmd.java_opts" displayName="Java Options"
+ description="These are the java options passed in before the main class"/>
+ <c:simple-property name="vm.starter.minHeapSize" displayName="Minimum Heap Size (MB)" required="false"
+ description="The bind address, when specified determines what address the vm will be bound to."/>
+ <c:simple-property name="vm.starter.maxHeapSize" type="integer" displayName="Maximum Heap Size (MB)" required="false"
+ description="The maximum heap size, in megabytes, to be used for this VM. If no value is provided for this property, the default property value from the configuration is used; if no value is specified anywhere, no maximum heap size will be set."/>
+ <c:simple-property name="vm.bind.address" type="string" displayName="VM Bind Address" required="false"
+ description="The bind address, when specified determines what address the vm will be bound to."/>
+ <c:simple-property name="vm.unicast.port" type="integer" displayName="Cluster Port for Unicast"
+ description="The port number for the process when unicast based clustering is used."/>
+ <c:simple-property name="vm.minPort" type="integer" displayName="Min Port Number"
+ description="Min port number"/>
+
+ </c:group>
+ <c:group name="tuning" displayName="Tuning">
+
+ <c:simple-property name="vm.timetolive" type="integer" displayName="Socket Worker Thread Time-To-Live (ms)"
+ description="Time-to-live (in milliseconds) for threads used to do work on client requests."/>
+ <c:simple-property name="vm.maxThreads" type="integer" displayName="Max Threads" required="false"
+ description="Maximum socket listener threads.">
+ <c:defaultValueDescription>If nothing is specified, the default of 64 will be used.
+ </c:defaultValueDescription>
+ </c:simple-property>
+ <c:simple-property name="vm.inputBufferSize" type="integer" displayName="Socket Input BufferSize"
+ description="The size of socket buffer used when reading."/>
+ <c:simple-property name="vm.forced.shutdown.time" type="integer" displayName="VM Forced Shutdown Time (secs)"
+ description="The the number of seconds the VM will wait until it will perform a force shutdown."/>
+ <c:simple-property name="vm.outputBufferSize" type="integer" displayName="Socket Output BufferSize"
+ description="The size of the socket buffer used when writing."/>
+
+ </c:group>
+ </resource-configuration>
+
+
+ <service name="Connectors"
+ discovery="ConnectorDiscoveryComponent"
+ class="ConnectorComponent">
+
+ <resource-configuration>
+ <c:group name="advanced" displayName="Advanced">
+
+ <c:list-property name="config-property"
+ displayName="Config Property"
+ description="Configuration Properties"
+ required="false">
+ <c:map-property name="property-values">
+ <c:simple-property name="config-property-name"
+ displayName="Name"
+ description="Name of the Configuration Property"
+ required="true"/>
+ <c:simple-property name="config-property-type"
+ displayName="Type"
+ description="Type of the Configuration Property"
+ required="true"/>
+ <c:simple-property name="config-property-value"
+ displayName="Value"
+ description="Value of the Configuration Property"
+ required="true"/>
+ </c:map-property>
+ </c:list-property>
+
+ </c:group>
+ </resource-configuration>
+
+ <operation name="restartConnector"
+ displayName="Re-start Connector"
+ description="Start/re-start this connector binding" />
+ <operation name="stopConnector"
+ displayName="Stop Connector"
+ description="Stop this connector binding">
+ <parameters>
+ <c:simple-property name="stopNow" type="boolean"
+ default="true"
+ description="If true, stop the connector binding forcefully. If false, wait until any pending work is completed." />
+ </parameters>
+ </operation>
+ </service>
+
+ <service name="Services"
+ discovery="ServiceDiscoveryComponent"
+ class="ServiceComponent">
+
+ <resource-configuration>
+ <c:group name="advanced" displayName="Advanced">
+
+ <c:list-property name="config-property"
+ displayName="Config Property"
+ description="Configuration Properties"
+ required="false">
+ <c:map-property name="property-values">
+ <c:simple-property name="config-property-name"
+ displayName="Name"
+ description="Name of the Configuration Property"
+ required="true"/>
+ <c:simple-property name="config-property-type"
+ displayName="Type"
+ description="Type of the Configuration Property"
+ required="true"/>
+ <c:simple-property name="config-property-value"
+ displayName="Value"
+ description="Value of the Configuration Property"
+ required="true"/>
+ </c:map-property>
+ </c:list-property>
+
+ </c:group>
+ </resource-configuration>
+
+ <operation name="restart"
+ displayName="Re-start Service"
+ description="Start/re-start this service" />
+ <operation name="stop"
+ displayName="Stop Service"
+ description="Stop this service">
+ <parameters>
+ <c:simple-property name="stopNow" type="boolean"
+ default="true"
+ description="If true, stop the servie forcefully. If false, wait until any pending work is completed." />
+ </parameters>
+ </operation>
+ </service>
+
+ </service> <!-- end of VM -->
+
+ </server> <!-- end of Host -->
+
+ </server> <!-- end of System -->
+
+ <server name="Security"
+ discovery="NodeDiscoveryComponent"
+ description="Security"
+ class="SecurityComponent"
+ singleton="true">
+
+ <resource-configuration>
+ <c:group name="configuration" displayName="Configuration">
+ <c:simple-property name="enabled" type="boolean" summary="true" default="false" required="true"
+ description="A flag indicating whether or not security is enabled for this system."/>
+ <c:simple-property name="username" required="false" description="The name of the administrative principal (i.e. user) to authenticate."/>
+ <c:simple-property name="password" type="password" required="false"
+ description="The credentials (i.e. password) that should be used to authenticate the administrative principal."/>
+ </c:group>
+ </resource-configuration>
+ </server> <!-- End of security -->
+
+ </server> <!-- end of Platform -->
+
+
+
+<!--
+
+
+ <service name="Connector Types"
+ subCategory="Resources"
+ discovery="ResourceDiscoveryComponent"
+ class="ResourceComponent"
+ description="Connector Types"
+ createDeletePolicy="both"
+ creationDataType="content">
+
+ <operation name="getProperties"
+ displayName="View properties"
+ description="List the properties">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property name="Name" type="string"
+ description="The name of this property" />
+ <c:simple-property name="Connector Type" type="string"
+ description="The type of connector that defines this data source" />
+ <c:simple-property name="Default" type="string"
+ description="The default value when not defined by the user" />
+ <c:simple-property name="Masked" type="boolean"
+ description="Indicates if the property value requires masking after being entered. A password would be a good example of a value needing masking." />
+ <c:simple-property name="Descritpion" type="string"
+ description="The property description" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <content name="file" displayName="CDK File" category="deployable" isCreationType="true">
+ <configuration>
+ </configuration>
+ </content>
+ </service>
+-->
+
+</plugin>
\ No newline at end of file
Property changes on: trunk/console/src/resources/embedded/META-INF/rhq-plugin.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/resources/enterprise/META-INF/rhq-plugin.xml
===================================================================
--- trunk/console/src/resources/enterprise/META-INF/rhq-plugin.xml (rev 0)
+++ trunk/console/src/resources/enterprise/META-INF/rhq-plugin.xml 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,348 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ * (c) 2008 Varsity Gateway LLC.
+ * All rights reserved.
+ *
+ * This descriptor is used for deploying JBEDSP to JON for enterprise use
+ * -->
+
+<plugin name="MetaMatrixPlugin" displayName="MetaMatrix Plugin"
+ package="com.metamatrix.rhq.plugin" version="2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin" xmlns:c="urn:xmlns:rhq-configuration">
+
+ <server name="MetaMatrix System"
+ discovery="MetaMatrixSystemDiscoveryComponent"
+ class="MetaMatrixSystemComponent" description="MetaMatrix System"
+ singleton="true">
+
+ <operation name="bounceSystem"
+ displayName="Bounce MetaMatrix System"
+ description="Stop and restart the MetaMatrix system">
+ <parameters>
+ <c:simple-property name="waitUntilFinished"
+ type="boolean" default="false"
+ description="If true, this method waits until the operation is finished before returning. This may take a long time to complete. If false, this method returns immediately, even though the operation may not be finished." />
+ </parameters>
+ </operation>
+
+ <operation name="listUsers"
+ displayName="View current user sessions"
+ description="List current user sessions connected to this MetaMatrix System">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string"
+ description="The username for the user of this session" />
+ <c:simple-property
+ displayName="Application Name" name="getApplicationName"
+ type="string"
+ description="The name of the application this user is accessing MetaMatrix through" />
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string"
+ description="The id for this session" />
+ <c:simple-property displayName="VDB Name"
+ name="getVDBName" type="string"
+ description="The name of the VDB the user is connected to" />
+ <c:simple-property displayName="VDB Version"
+ name="getVDBVersion" type="string"
+ description="The version of the VDB the user is connected to" />
+ <c:simple-property displayName="Product Name"
+ name="getProductName" type="string"
+ description="The product name" />
+ <c:simple-property displayName="IP Address"
+ name="getIPAddress" type="string"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Host Name"
+ name="getHostName" type="string"
+ description="The host name for this user's connection" />
+ <c:simple-property displayName="Last Ping Time"
+ name="getLastPingTime" type="string"
+ description="The last time this client was ping'd" />
+ <c:simple-property displayName="State"
+ name="getStateAsString" type="string"
+ description="The current state of this session" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <operation name="listQueries" displayName="View current queries"
+ description="List current queries executing against the MetaMatrix System">
+ <parameters>
+ <c:simple-property name="includeSourceQueries"
+ type="boolean" default="true"
+ description="If true, source queries will be included in the results. If false, only top-level MetaMatrix queries will be included in the results." />
+ </parameters>
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string"
+ description="The username for the user that submitted this query" />
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string"
+ description="The id for the session" />
+ <c:simple-property displayName="Request ID"
+ name="getRequestID" type="string"
+ description="The id for the request" />
+ <c:simple-property displayName="Start Time"
+ name="getCreated" type="string"
+ description="The time this query has been running" />
+ <c:simple-property displayName="Transaction ID"
+ name="getTransactionID" type="string"
+ description="The version of the VDB the user is connected to" />
+ <c:simple-property displayName="SQL String"
+ name="getSqlCommand" type="string"
+ description="The SQL string for this query" />
+ <c:simple-property
+ displayName="Connector Binding Name"
+ name="getConnectorBindingName" type="string"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Node ID"
+ name="getNodeID" type="string"
+ description="The node ID of this query" />
+ <c:simple-property displayName="Source Request"
+ name="isSource" type="string"
+ description="If false this is the top level query. If true this a physical source query." />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <operation name="listLongRunningQueries"
+ displayName="View current long running queries"
+ description="List current queries executing against the MetaMatrix System that have surpassed the long running query threshhold">
+ <parameters>
+ <c:simple-property name="includeSourceQueries"
+ type="boolean" default="true"
+ description="If true, source queries will be included in the results. If false, only top-level MetaMatrix queries will be included in the results." />
+ </parameters>
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property displayName="User Name"
+ name="getUserName" type="string"
+ description="The username for the user that submitted this query" />
+ <c:simple-property displayName="Session ID"
+ name="getSessionID" type="string"
+ description="The name of the resource whose availability is being reported" />
+ <c:simple-property displayName="Request ID"
+ name="getRequestID" type="string"
+ description="The id for the request" />
+ <c:simple-property displayName="Start Time"
+ name="getCreated" type="string"
+ description="The time this query has been running" />
+ <c:simple-property displayName="Transaction ID"
+ name="getTransactionID" type="string"
+ description="The version of the VDB the user is connected to" />
+ <c:simple-property displayName="SQL String"
+ name="getSqlCommand" type="string"
+ description="The SQL string for this query" />
+ <c:simple-property
+ displayName="Connector Binding Name"
+ name="getConnectorBindingName" type="string"
+ description="The IP Address for this user's connection" />
+ <c:simple-property displayName="Node ID"
+ name="getNodeID" type="string"
+ description="The node ID of this query" />
+ <c:simple-property displayName="Source Request"
+ name="isSource" type="string"
+ description="If false this is the top level query. If true this a physical source query." />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <operation name="killRequest" displayName="Terminate query"
+ description="Terminate the processing of a query and it's source queries">
+ <parameters>
+ <c:simple-property displayName="SessionID|RequestID"
+ name="requestID" type="string" required="true"
+ description="The IDs of the session|request to terminate (use format = sessionID|requestID)" />
+ </parameters>
+ </operation>
+
+ <operation name="listVDBs" displayName="View VDBs"
+ description="List VDBs in this MetaMatrix System">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property displayName="Name"
+ name="getName" type="string" description="The name of this VDB" />
+ <c:simple-property displayName="Version"
+ name="getVDBVersion" type="string"
+ description="The version of this VDB" />
+ <c:simple-property displayName="State"
+ name="getStateAsString" type="string"
+ description="The state of this VDB" />
+ <c:simple-property displayName="Has WSDL"
+ name="hasWSDL" type="string"
+ description="If true, this VDB contains a WSDL file" />
+ <c:simple-property
+ displayName="Has Materialized Views" name="hasMaterializedViews"
+ type="string"
+ description="If true, this VDB contains one or more materialized views" />
+ <c:simple-property displayName="Created Date"
+ name="getCreatedDate" type="string"
+ description="The creation date of this VDB" />
+ <c:simple-property displayName="Created By"
+ name="getCreatedBy" type="string"
+ description="The user that created this VDB" />
+ <c:simple-property displayName="Versioned Date"
+ name="getVersionedDate" type="string"
+ description="The version date of this VDB" />
+ <c:simple-property displayName="Versioned By"
+ name="getVersionedBy" type="string"
+ description="The user that versioned this VDB" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <operation name="getProperties"
+ displayName="View system properties"
+ description="List the system properties of this MetaMatrix System">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property name="Name" type="string"
+ description="The name of this property" />
+ <c:simple-property name="Value" type="string"
+ description="The value of this property" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <operation name="getHostProperties"
+ displayName="View host properties"
+ description="List the host properties of this MetaMatrix System">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property name="Name" type="string"
+ description="The name of this property" />
+ <c:simple-property name="Value" type="string"
+ description="The value of this property" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <metric displayName="Query Count" defaultOn="true"
+ displayType="summary" category="throughput" property="queryCount"
+ description="The number of queries for a given point in time" />
+
+ <metric displayName="Long Running Queries" defaultOn="true"
+ displayType="summary" category="performance"
+ property="longRunningQueries"
+ description="The number of queries that have been running longer than the limit set for queries. The default is 60 minutes, but this may be overridden by the 'longRunningQueryTime' system variable." />
+
+ <metric displayName="Session Count" defaultOn="true"
+ displayType="summary" category="throughput" property="sessionCount"
+ description="The number of user connections for a given point in time" />
+
+ <resource-configuration>
+ <c:group name="general" displayName="General" hiddenByDefault="false">
+ <c:description>Query Configuration</c:description>
+ <c:simple-property name="longrunning.query.limit" type="string" readOnly="true" required="true" displayName="Long Running Query limit" description="The value (in seconds) to use to determine if a query is to be considered 'long running'.">
+ </c:simple-property>
+ </c:group>
+ </resource-configuration>
+
+ <server name="MetaMatrix Process"
+ discovery="MetaMatrixServerDiscoveryComponent"
+ class="MetaMatrixServerComponent"
+ description="MetaMatrix Server instance">
+
+ <plugin-configuration>
+ <c:group name="event" displayName="Process Log Tracking">
+ <c:simple-property name="enabled" type="boolean" summary="true" default="true" required="true"
+ description="A flag indicating whether of not this log Event source is currently
+ enabled (i.e. whether the associated log file should be tailed for
+ new entries)."/>
+ <c:simple-property name="minimumSeverity" required="true" default="ERROR"
+ description="The minimum severity of Events that should be collected for this
+ source. The default is ERROR.">
+ <c:property-options>
+ <c:option name="DEBUG" value="DEBUG"/>
+ <c:option name="INFO" value="INFO"/>
+ <c:option name="WARNING" value="WARNING"/>
+ <c:option name="ERROR" value="ERROR" default="true"/>
+ </c:property-options>
+ </c:simple-property>
+ </c:group>
+ </plugin-configuration>
+
+ <operation name="getProperties"
+ displayName="View process properties"
+ description="List the process properties of this vm instance">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property name="Name" type="string"
+ description="The name of this property" />
+ <c:simple-property name="Value"
+ type="string" description="The value of this property" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+
+ <metric displayName="Query High Water Mark" defaultOn="true"
+ displayType="summary" category="utilization"
+ property="highWatermark"
+ description="High water mark for queries in the Socket Worker Queue" />
+
+ <event name="errorLogEntry" description="an entry in a log file"/>
+ <!-- Ted Jones - 06/19/08
+ Commenting out current threads metric until http://jira.jboss.org/jira/browse/JBEDSP-426 is resolved. -->
+ <!-- <metric displayName="Current Threads"
+ defaultOn="true"
+ displayType="summary"
+ category="utilization"
+ property="threadCount"
+ description="The number of active threads in the Socket Worker Queue"/> -->
+
+ <service name="Connectors"
+ discovery="MetaMatrixConnectorDiscoveryComponent"
+ class="MetaMatrixConnectorComponent">
+ <operation name="getProperties"
+ displayName="View connector properties"
+ description="List the properties of this connector">
+ <results>
+ <c:list-property name="list">
+ <c:map-property name="map">
+ <c:simple-property name="Name"
+ type="string" description="The name of this property" />
+ <c:simple-property name="Value"
+ type="string" description="The value of this property" />
+ </c:map-property>
+ </c:list-property>
+ </results>
+ </operation>
+ <operation name="restartConnector"
+ displayName="Re-start Connector"
+ description="Start/re-start this connector binding" />
+ <operation name="stopConnector"
+ displayName="Stop Connector"
+ description="Stop this connector binding">
+ <parameters>
+ <c:simple-property name="stopNow" type="boolean"
+ default="true"
+ description="If true, stop the process forcefully. If false, wait until any pending work is completed." />
+ </parameters>
+ </operation>
+ </service>
+
+ </server>
+ <server name="Host Controller"
+ discovery="MetaMatrixHostControllerDiscoveryComponent"
+ class="MetaMatrixHostControllerComponent"
+ description="MetaMatrix Host Controller">
+ </server>
+ </server>
+</plugin>
\ No newline at end of file
Property changes on: trunk/console/src/resources/enterprise/META-INF/rhq-plugin.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/test/java/org/teiid/rhq/AllTests.java
===================================================================
--- trunk/console/src/test/java/org/teiid/rhq/AllTests.java (rev 0)
+++ trunk/console/src/test/java/org/teiid/rhq/AllTests.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,34 @@
+/*
+ * Copyright � 2000-2008 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.rhq;
+
+import org.teiid.rhq.comm.impl.TestConnectionPool;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+
+/**
+ * @since 1.0
+ */
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.runAndWait(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for com.metamatrix.rhq"); //$NON-NLS-1$
+ //$JUnit-BEGIN$
+ suite.addTest(TestConnectionPool.suite());
+
+ //$JUnit-END$
+ return suite;
+ }
+
+
+
+}
Property changes on: trunk/console/src/test/java/org/teiid/rhq/AllTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/test/java/org/teiid/rhq/StartingEnvironmentConstants.java
===================================================================
--- trunk/console/src/test/java/org/teiid/rhq/StartingEnvironmentConstants.java (rev 0)
+++ trunk/console/src/test/java/org/teiid/rhq/StartingEnvironmentConstants.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,39 @@
+/*
+ * Copyright � 2000-2008 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.rhq;
+
+
+
+/**
+ * @since 4.3
+ */
+public interface StartingEnvironmentConstants {
+
+ public static final String INSTALL_DIR = "D:/apps/MetaMatrix/enterpriseserver/5.5.3/073008"; //$NON-NLS-1$
+ public static final String PORT = "31000"; //$NON-NLS-1$
+ public static final String USERNAME = "metamatrixadmin"; //$NON-NLS-1$
+ public static final String PASSWORD = "mm"; //$NON-NLS-1$
+
+ public static final String INSTALL_DIR2 = "D:/metamatrix/5.5.3/server_0721b"; //$NON-NLS-1$
+ public static final String PORT2 = "32000"; //$NON-NLS-1$
+
+
+
+
+ public static final String SINGLE_SYSTEM_PARM =
+ INSTALL_DIR + "," + //$NON-NLS-1$
+ PORT + "," + //$NON-NLS-1$
+ USERNAME + "," + //$NON-NLS-1$
+ PASSWORD;
+
+ public static final String TWO_SYSTEM_PARM = SINGLE_SYSTEM_PARM + ";" + //$NON-NLS-1$
+ INSTALL_DIR2 + "," + //$NON-NLS-1$
+ PORT2 + "," + //$NON-NLS-1$
+ USERNAME + "," + //$NON-NLS-1$
+ PASSWORD;
+
+
+
+}
Property changes on: trunk/console/src/test/java/org/teiid/rhq/StartingEnvironmentConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java
===================================================================
--- trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java (rev 0)
+++ trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,226 @@
+/*
+ * Copyright � 2000-2008 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.rhq.comm.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.rhq.comm.Component;
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionPool;
+import org.teiid.rhq.comm.ExecutedResult;
+
+
+/**
+ * @since 6.2
+ */
+public class FakeConnection implements Connection{
+
+ public static int NUM_CONNECTORS = 3;
+ public static int NUM_VMS = 2;
+ public static int NUM_HOSTS = 1;
+
+ private static final String HOST_ID = "Host_id_1"; //$NON-NLS-1$
+
+ private String installDir = null;
+ private ConnectionPool pool;
+ private Properties envProps = null;
+
+ public FakeConnection(ConnectionPool pool, Properties env) {
+ this.pool = pool;
+ this.envProps = env;
+
+ }
+
+
+
+ @Override
+ public Collection<Component> discoverComponents(String componentType,
+ String identifier) throws ConnectionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+ @Override
+ public void executeOperation(ExecutedResult result, Map valueMap)
+ throws ConnectionException {
+ // TODO Auto-generated method stub
+
+ }
+
+
+
+ @Override
+ public String getKey() throws Exception {
+ // TODO Auto-generated method stub
+ return "fakekey";
+ }
+
+
+
+ @Override
+ public Object getMetric(String componentType, String identifier,
+ String metric, Map valueMap) throws ConnectionException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#isValid()
+ * @since 6.2
+ */
+ public boolean isValid() {
+ return true;
+ }
+
+ /**
+ * @throws Exception
+ * @see com.metamatrix.rhq.comm.Connection#close()
+ * @since 6.2
+ */
+ public void close() {
+ try {
+ pool.close(this);
+ } catch (Exception err) {
+ throw new RuntimeException(err);
+
+ }
+ }
+
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getConnectors(java.lang.String)
+ * @since 6.2
+ */
+ public Collection<Component> getConnectors(String vmname) throws ConnectionException {
+ Collection<Component> vms = getVMs();
+ Collection<Component> cs = new ArrayList(5);
+ for (Iterator vmIt=vms.iterator(); vmIt.hasNext();) {
+ Component vm = (Component) vmIt.next();
+ for (int i = 0; i < NUM_VMS; i++) {
+ ComponentImpl c = new ComponentImpl();
+ c.setSystemKey(this.installDir);
+ c.setIdentifier(vm.getIdentifier() + "|VM_id_" + i); //$NON-NLS-1$
+ c.setName("VM_id_" + i); //$NON-NLS-1$
+ cs.add(c);
+ }
+ }
+
+ return cs;
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getEnvironment()
+ * @since 6.2
+ */
+ public Properties getEnvironment() throws Exception {
+ return this.envProps;
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getHost()
+ * @since 6.2
+ */
+ public Component getHost() throws ConnectionException {
+ ComponentImpl c = new ComponentImpl();
+ c.setSystemKey(this.installDir);
+ c.setIdentifier(HOST_ID);
+ c.setName(HOST_ID );
+ c.setPort("1"); //$NON-NLS-1$
+ return c;
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getInstallationDirectory()
+ * @since 6.2
+ */
+ public String getInstallationDirectory() throws Exception {
+ return installDir;
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getMetric(java.lang.String, java.lang.String, java.util.Map)
+ * @since 6.2
+ */
+ public Object getMetric(String componentType,
+ String metric,
+ Map valueMap) throws ConnectionException {
+ return null;
+ }
+
+
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getProperties(java.lang.String, java.lang.String)
+ * @since 6.2
+ */
+ public Properties getProperties(String resourceType,
+ String identifier) throws ConnectionException {
+ return null;
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getProperty(java.lang.String, java.lang.String)
+ * @since 6.2
+ */
+ public String getProperty(String identifier,
+ String property) throws ConnectionException {
+ return this.envProps.getProperty(property);
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#getVMs()
+ * @since 6.2
+ */
+ public Collection<Component> getVMs() throws ConnectionException {
+
+
+ Component host = getHost();
+ Collection cs = new ArrayList(5);
+ for (int i = 0; i < NUM_VMS; i++) {
+ ComponentImpl c = new ComponentImpl();
+ c.setSystemKey(this.installDir);
+ c.setIdentifier(host.getIdentifier() + "|VM_id_" + i); //$NON-NLS-1$
+ c.setName("VM_id_" + i); //$NON-NLS-1$
+ c.setPort(String.valueOf(i));
+ cs.add(c);
+ }
+
+ return cs;
+
+ }
+
+ public Collection<Component> getVDBs(List fieldNameList) throws ConnectionException {
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#isAlive()
+ * @since 6.2
+ */
+ public boolean isAlive() {
+ return true;
+ }
+
+ /**
+ * @see com.metamatrix.rhq.comm.Connection#isAvailable(java.lang.String, java.lang.String)
+ * @since 6.2
+ */
+ public Boolean isAvailable(String componentType,
+ String identifier) throws ConnectionException {
+ return true;
+ }
+
+}
Property changes on: trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java
===================================================================
--- trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java (rev 0)
+++ trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,59 @@
+package org.teiid.rhq.comm.impl;
+
+
+import java.util.Properties;
+
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionFactory;
+import org.teiid.rhq.comm.ConnectionPool;
+
+
+
+
+public class FakeConnectionFactory implements
+ ConnectionFactory {
+
+ static boolean createdfactory = false;
+ private static Properties connEnv;
+ private ConnectionPool pool;
+
+ public Connection createConnection(){
+
+ return new FakeConnection(pool, connEnv);
+
+ }
+
+
+
+
+ @Override
+ public String getURL() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+
+ @Override
+ public void initialize(Properties env, ConnectionPool connectionPool)
+ throws ConnectionException {
+ connEnv = env;
+ this.pool = connectionPool;
+ createdfactory = true;
+
+ }
+
+
+ public void closeConnection(Connection connection) {
+
+ }
+
+
+ public String getProperty(String key) {
+ return connEnv.getProperty(key);
+ }
+
+
+}
Property changes on: trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java
===================================================================
--- trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java (rev 0)
+++ trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,60 @@
+package org.teiid.rhq.comm.impl;
+
+
+import java.util.Properties;
+
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionException;
+import org.teiid.rhq.comm.ConnectionFactory;
+import org.teiid.rhq.comm.ConnectionPool;
+
+
+
+public class FakeInvalidConnectionFactory implements
+ ConnectionFactory {
+
+ static boolean createdfactory = false;
+ private static Properties connEnv;
+ private ConnectionPool pool;
+
+ public Connection createConnection(){
+
+ Connection result = new InvalidConnectionImpl("INVALIDKEY", connEnv, pool);
+
+
+ return result;
+ }
+
+
+
+
+ @Override
+ public String getURL() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+
+ @Override
+ public void initialize(Properties env, ConnectionPool connectionPool)
+ throws ConnectionException {
+ connEnv = env;
+ this.pool = connectionPool;
+ createdfactory = true;
+
+ }
+
+
+ public void closeConnection(Connection connection) {
+
+ }
+
+
+ public String getProperty(String key) {
+ return connEnv.getProperty(key);
+ }
+
+
+}
Property changes on: trunk/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java
===================================================================
--- trunk/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java (rev 0)
+++ trunk/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java 2009-07-31 13:15:35 UTC (rev 1210)
@@ -0,0 +1,359 @@
+/*
+ * Copyright � 2000-2008 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.rhq.comm.impl;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.teiid.rhq.comm.Connection;
+import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.comm.ConnectionPool;
+//import org.teiid.rhq.embedded.pool.ConnectionPoolImpl;
+
+import org.teiid.rhq.enterprise.pool.ConnectionPoolImpl;
+
+
+
+
+/**
+ * @since 4.3
+ */
+public class TestConnectionPool extends TestCase {
+ static {
+ // System.setProperty(SingletonConnectionManager.INSTALL_SERVER_PROP,StartingEnvironmentConstants.SINGLE_SYSTEM_PARM);
+
+ // reset the conn mager for the next test case class
+
+ }
+
+ private boolean failure = false;
+ int count;
+
+ /**
+ * This suite of all tests could be defined in another class but it seems easier to
+ * maintain it here.
+ */
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("TestConnectionPool"); //$NON-NLS-1$
+ suite.addTestSuite(TestConnectionPool.class);
+ return suite;
+ }
+
+
+ // ################################## MAIN ################################
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ /**
+ * @since 1.0
+ */
+// public static void main(final String[] arguments) {
+// try {
+//
+// TestConnectionPool test = new TestConnectionPool();
+// test.runTest();
+//
+//
+// }catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
+
+// public void runTest() throws Exception {
+// testSimple();
+// testSecond();
+// testThreading();
+// }
+
+ public void testSimple() throws Exception {
+ log("Start simpleTest...");
+ failure = false;
+
+ Properties props = new Properties();
+ props.setProperty(ConnectionPool.CONNECTION_FACTORY, "org.teiid.rhq.comm.impl.FakeConnectionFactory");
+
+ ConnectionPool pool = new ConnectionPoolImpl();
+ pool.initialize(props, this.getClass().getClassLoader());
+
+ if (!FakeConnectionFactory.createdfactory) {
+ logError("Didn't use the fake factory");
+ }
+
+ Connection conn = pool.getConnection();
+
+ int cnt = pool.getAvailableConnectionCount();
+ if (cnt != 0) {
+ logError("Available count should have been 0, but was " + cnt);
+ }
+
+
+ cnt = pool.getConnectionsInUseCount();
+ if (cnt != 1) {
+ logError("Connections in use should have been 1, but was " + cnt);
+ }
+
+ pool.close(conn);
+
+ cnt = pool.getConnectionsInUseCount();
+ if (cnt != 0) {
+ logError("Connections in use should have been 0 after checkin, but was " + cnt);
+ }
+
+ cnt = pool.getAvailableConnectionCount();
+ if (cnt != 1) {
+ logError("Available count should have been 1 after checking, but was " + cnt);
+ }
+
+ pool.shutdown();
+ log("Was simpleTest a success " + !failure );
+ }
+
+ public void testSecond() throws Exception {
+ log("Start secondTest...");
+ failure = false;
+ Properties props = new Properties();
+ props.setProperty(ConnectionPool.CONNECTION_FACTORY, "org.teiid.rhq.comm.impl.FakeConnectionFactory");
+
+ ConnectionPool pool = new ConnectionPoolImpl();
+ pool.initialize( props, this.getClass().getClassLoader());
+
+ if (!FakeConnectionFactory.createdfactory) {
+ logError("Didn't use the fake factory");
+ }
+
+ Connection conn = pool.getConnection();
+ Connection conn2 = pool.getConnection();
+ Connection conn3 = pool.getConnection();
+
+ validateAvailCnt(pool, 0);
+
+ validateInUseCnt(pool, 3);
+
+
+ pool.close(conn);
+
+ validateAvailCnt(pool, 1);
+
+ validateInUseCnt(pool, 2);
+
+
+ Connection conn4 = pool.getConnection();
+ Connection conn5 = pool.getConnection();
+
+ validateAvailCnt(pool, 0);
+
+ validateInUseCnt(pool, 4);
+
+ pool.close(conn5);
+ pool.close(conn3);
+ pool.close(conn2);
+ pool.close(conn4);
+
+ validateAvailCnt(pool, 4);
+
+ validateInUseCnt(pool, 0);
+
+ pool.shutdown();
+ log("Was secondTest a success " + !failure );
+ }
+
+ private void validateInUseCnt(ConnectionPool pool, int cnt) {
+
+// int incnt = pool.getConnectionsInUseCount();
+// if (incnt != cnt) {
+// logError("Connections in use should have been " + cnt + " , but was " + incnt);
+// }
+ }
+
+ private void validateAvailCnt(ConnectionPool pool, int cnt) {
+
+// int incnt = pool.getAvailableConnectionCount();
+// if (incnt != cnt) {
+// logError("Available count should have been " + cnt + " , but was " + incnt);
+// }
+ }
+
+ public void testThreading() throws Exception {
+ failure = false;
+ log("Start threadingTest...");
+
+ Properties props = new Properties();
+ props.setProperty(ConnectionPool.CONNECTION_FACTORY, "org.teiid.rhq.comm.impl.FakeConnectionFactory");
+ props.setProperty(ConnectionConstants.PASSWORD, "PW");
+ props.setProperty(ConnectionConstants.USERNAME, "USERNAME");
+
+ ConnectionPool pool = new ConnectionPoolImpl();
+ pool.initialize( props, this.getClass().getClassLoader());
+
+
+ int threadCnt = 10;
+// int max_size = 1;
+ // int expectedNumErrors = threadCnt - max_size;
+
+ TimeOutThread[] ts = new TimeOutThread[threadCnt];
+
+ for (count = 0; count < threadCnt; count++) {
+ ts[count] = new TimeOutThread(pool, 10, count);
+ }
+
+ for(int k = 0; k < threadCnt; k++){
+ ts[k].start();
+ }
+
+ try {
+ for(int k = 0; k < threadCnt; k++){
+ ts[k].join();
+ }
+ } catch (InterruptedException e) {
+ }
+
+ for(int k = 0; k < threadCnt; k++){
+ if (ts[k].hasException()) {
+ Exception e = ts[k].getException();
+
+ logError("Exception " + e.getMessage());
+
+
+ }
+ // which thread
+ int pc = ts[k].getProcessCnt();
+
+ // number of connections suppose to process per thread
+ int ptc = ts[k].getPerThreadCnt();
+
+ // the number of connection actually processed
+ int mx = ts[k].getMaxProcessedCnt();
+
+ // the end count of the connection left after close is suppose to be called
+ int ct = ts[k].getConnectionCount();
+ if (ct != 0) {
+ logError("Thread " + pc + " did have the connections go back down to zero");
+ }
+ if (ptc != mx) {
+ logError("PerThreadCnt " + ptc + ", but only successfully processed " + mx);
+ } else {
+ log("Process " + pc + " for thread # " + k);
+ }
+
+
+ }
+
+ log("Was threadingTest a success " + !failure );
+
+
+ }
+
+
+
+ private void logError(String msg) {
+ failure = true;
+ System.out.println(msg);
+ }
+
+ private void log(String msg) {
+ System.out.println(msg);
+ }
+
+ protected class TimeOutThread extends BaseThread{
+ private ConnectionPool pool;
+ private int connCnt = 0;
+ private int processCnt = 0;
+ private int maxCnt = 0;
+
+
+ public TimeOutThread(ConnectionPool connpool, int connections, int processcnt) {
+ super(connections);
+ this.pool = connpool;
+ this.processCnt = processcnt;
+
+
+ }
+ public int getProcessCnt() {
+ return processCnt;
+ }
+
+ public int getMaxProcessedCnt() {
+ return maxCnt;
+ }
+ public int getConnectionCount() {
+ return this.connCnt;
+ }
+
+ public void run(){
+ // DO NOT call resource.close(), all the resources should remain
+ // checkedout to cause the next resource request to timeout.
+
+
+ for (int i=0; i < perThreadCnt; i++ ) {
+ Connection conn = null;
+ try {
+ conn = pool.getConnection();
+ ++connCnt;
+ ++maxCnt;
+
+ yield();
+// Properties psrops =conn.
+// if (psrops == null || psrops.isEmpty()) {
+// setException(new Exception("Null Environment"));
+// }
+// if (conn.getProperty(ConnectionConstants.USERNAME) == null) {
+// setException(new Exception("No UserName"));
+// }
+// if (psrops.size() < 3) {
+// setException(new Exception("NOt Enough Properties"));
+// System.out.println(psrops);
+// }
+
+ } catch (Exception toe) {
+ setException(toe);
+
+ }
+
+ // yield to the other thread to checkout instance, which should timeout
+ try {
+ pool.close(conn);
+ --connCnt;
+ } catch (Exception err) {
+ setException(err);
+ }
+ }
+ }
+ }
+
+ protected class BaseThread extends Thread{
+ protected String objName = "Thread " + count; //$NON-NLS-1$
+ protected int perThreadCnt = 1;
+ private Exception t = null;
+
+
+ public BaseThread(int iterationCnt) {
+ perThreadCnt = iterationCnt;
+ }
+
+ public int getPerThreadCnt() {
+ return perThreadCnt;
+ }
+
+ public Exception getException() {
+ return t;
+ }
+
+ public void setException(Exception te) {
+ t = te;
+ }
+
+ public boolean hasException() {
+ return (t==null ? false : true);
+ }
+
+ }
+
+}
Property changes on: trunk/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 4 months
teiid SVN: r1209 - in trunk/console/src: main/java and 18 other directories.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-07-31 09:12:58 -0400 (Fri, 31 Jul 2009)
New Revision: 1209
Added:
trunk/console/src/main/java/
trunk/console/src/main/java/org/
trunk/console/src/main/java/org/teiid/
trunk/console/src/main/java/org/teiid/rhq/
trunk/console/src/main/java/org/teiid/rhq/admin/
trunk/console/src/main/java/org/teiid/rhq/admin/utils/
trunk/console/src/main/java/org/teiid/rhq/comm/
trunk/console/src/main/java/org/teiid/rhq/comm/impl/
trunk/console/src/main/java/org/teiid/rhq/embedded/
trunk/console/src/main/java/org/teiid/rhq/embedded/pool/
trunk/console/src/main/java/org/teiid/rhq/enterprise/
trunk/console/src/main/java/org/teiid/rhq/enterprise/pool/
trunk/console/src/main/java/org/teiid/rhq/plugin/
trunk/console/src/main/java/org/teiid/rhq/plugin/log/
trunk/console/src/main/java/org/teiid/rhq/plugin/objects/
trunk/console/src/main/java/org/teiid/rhq/plugin/util/
trunk/console/src/resources/embedded/
trunk/console/src/resources/embedded/META-INF/
trunk/console/src/resources/enterprise/
trunk/console/src/resources/enterprise/META-INF/
trunk/console/src/test/java/
trunk/console/src/test/java/org/
trunk/console/src/test/java/org/teiid/
trunk/console/src/test/java/org/teiid/rhq/
trunk/console/src/test/java/org/teiid/rhq/comm/
trunk/console/src/test/java/org/teiid/rhq/comm/impl/
trunk/console/src/test/java/org/teiid/rhq/enterprise/
trunk/console/src/test/java/org/teiid/rhq/enterprise/pool/
Log:
moving jbedsp-monitor project into teiid as the starting point for teiid-console
15 years, 4 months
teiid SVN: r1208 - in trunk/console: src and 1 other directory.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-07-31 09:03:45 -0400 (Fri, 31 Jul 2009)
New Revision: 1208
Added:
trunk/console/pom.xml
trunk/console/src/
trunk/console/src/assembly/
trunk/console/src/main/
trunk/console/src/resources/
trunk/console/src/test/
Log:
moving jbedsp-monitor project into teiid as the starting point for teiid-console
Added: trunk/console/pom.xml
===================================================================
--- trunk/console/pom.xml (rev 0)
+++ trunk/console/pom.xml 2009-07-31 13:03:45 UTC (rev 1208)
@@ -0,0 +1,347 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <parent>
+ <artifactId>teiid</artifactId>
+ <groupId>org.jboss.teiid</groupId>
+ <version>6.2.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-console</artifactId>
+ <name>TEIID Console</name>
+ <description>This project is for the RHQ plugin that supports the TEIID Console </description>
+
+ <properties>
+ <org.jboss.jopr.as4.version>1.2.0.GA</org.jboss.jopr.as4.version>
+ <org.jboss.jopr.as5.version>1.2.0.GA</org.jboss.jopr.as5.version>
+
+ <org.jboss.jopr.version>1.2.0.GA</org.jboss.jopr.version>
+
+ <apache.ant.version>1.7.0</apache.ant.version>
+
+ </properties>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!-- Fixes how test resources of a project can be used in projects dependent on it -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <!-- Specify the compiler options and settings -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <showDeprecation>false</showDeprecation>
+ <showWarnings>false</showWarnings>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*TestCase.java</include>
+ <include>**/*Test.java</include>
+ <include>**/Test*.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/Abstract*TestCase.java</exclude>
+ <!-- hack to prevent anonymous inner classes in Tests from being run as tests -->
+ <include>**/Test*$*.java</include>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>user.dir</name>
+ <value>${basedir}/target</value>
+ </property>
+ <property>
+ <name>java.io.tmpdir</name>
+ <value>${basedir}/target</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-2</version>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/binaries.xml</descriptor>
+ </descriptors>
+ <outputDirectory>target/distribution</outputDirectory>
+ <workDirectory>target/assembly/work</workDirectory>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!--
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>${apache.ant.version}</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>assemble-artifacts</id>
+ <phase>package</phase>
+ <configuration>
+ <tasks>
+ <property name="product.version" value="${project.version}" />
+ <property name="product.name" value="${project.name}" />
+ <ant antfile="src/assembly/assemble-artifacts.xml" />
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ -->
+
+ <!--
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dist-wars</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/</outputDirectory>
+
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.jopr</groupId>
+ <artifactId>jopr-embedded-jbas4</artifactId>
+ <version>${org.jboss.jopr.as4.version}</version>
+ <type>war</type>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.jboss.jopr</groupId>
+ <artifactId>jopr-embedded-jbas5</artifactId>
+ <version>${org.jboss.jopr.as5.version}</version>
+ <type>war</type>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ -->
+<!--
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>${apache.ant.version}</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>assembly-kit-jboss-as4</id>
+ <phase>package</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="target/jboss-as4-war"/>
+ <unzip src="target/jopr-embedded-jbas4-${org.jboss.jopr.as4.version}.war" dest="target/jboss-as4-war"/>
+
+ <mkdir dir="target/plugin-classes"/>
+
+
+ <unzip src="../jbedsp-plugin/target/distribution/jbedsp-plugin-${project.version}-binaries.jar" dest="target/jboss-as4-war/WEB-INF/lib"/>
+
+ <unzip src="../jbedsp-plugin/target/distribution/jbedsp-embedded-plugin-${project.version}.jar" dest="target/plugin-classes"/>
+ <unzip src="target/${project.name}-${project.version}.jar" dest="target/plugin-classes"/>
+ <jar destfile="target/jboss-as4-war/plugins/jbedsp-jopr-plugin-${project.version}.jar" basedir="target/plugin-classes"/>
+
+ <zip destfile="target/jopr-teiid-embedded-jbas4.war" basedir="target/jboss-as4-war" />
+
+ </tasks>
+
+ </configuration>
+
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>assembly-kit-jboss-as5</id>
+ <phase>package</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="target/jboss-as5-war"/>
+ <unzip src="target/jopr-embedded-jbas5-${org.jboss.jopr.as5.version}.war" dest="target/jboss-as5-war"/>
+
+ <mkdir dir="target/plugin-classes"/>
+
+ <unzip src="../jbedsp-plugin/target/distribution/jbedsp-plugin-${project.version}-binaries.jar" dest="target/jboss-as5-war/WEB-INF/lib"/>
+
+ <unzip src="../jbedsp-plugin/target/distribution/jbedsp-embedded-plugin-${project.version}.jar" dest="target/plugin-classes"/>
+ <unzip src="target/${project.name}-${project.version}.jar" dest="target/plugin-classes"/>
+ <jar destfile="target/jboss-as5-war/plugins/jbedsp-jopr-plugin-${project.version}.jar" basedir="target/plugin-classes"/>
+
+ <zip destfile="target/jopr-teiid-embedded-jbas5.war" basedir="target/jboss-as5-war" />
+ </tasks>
+
+ </configuration>
+
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ </executions>
+ </plugin>
+-->
+
+
+
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!--
+ Below are the core modules that are required dependencies of all
+ plugins
+ -->
+ <dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-core-domain</artifactId>
+ <version>${org.jboss.jopr.version}</version>
+ <scope>provided</scope>
+ <!--
+ provided by the agent/plugin-container
+ -->
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-core-plugin-api</artifactId>
+ <version>${org.jboss.jopr.version}</version>
+ <scope>provided</scope> <!-- provided by the agent/plugin-container -->
+ </dependency>
+
+ <dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-core-native-system</artifactId>
+ <version>${org.jboss.jopr.version}</version>
+ <scope>provided</scope> <!-- provided by the agent/plugin-container -->
+ </dependency>
+
+ <!--
+ TODO: This is a fix for the Javac bug requiring annotations to be
+ available when compiling dependent classes. It is fixed in JDK 6.
+ -->
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope> <!-- provided by the agent/plugin-container -->
+ </dependency>
+
+
+ <!--
+ TODO: This is a fix for the Javac bug requiring annotations to be
+ available when compiling dependent classes; it is fixed in JDK 6.
+ -->
+ <dependency>
+ <groupId>jboss.jboss-embeddable-ejb3</groupId>
+ <artifactId>hibernate-all</artifactId>
+ <version>1.0.0.Alpha9</version>
+ <scope>provided</scope> <!-- provided by the agent/plugin-container -->
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-client</artifactId>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-client-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-client-jdbc</artifactId>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.jopr</groupId>
+ <artifactId>jopr-embedded-jbas4</artifactId>
+ <type>war</type>
+ <version>${org.jboss.jopr.as4.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.jopr</groupId>
+ <artifactId>jopr-embedded-jbas5</artifactId>
+ <type>war</type>
+ <version>${org.jboss.jopr.as5.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ </dependency>
+
+
+ </dependencies>
+
+
+</project>
Property changes on: trunk/console/pom.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 4 months
teiid SVN: r1207 - trunk.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-07-31 07:42:05 -0400 (Fri, 31 Jul 2009)
New Revision: 1207
Added:
trunk/console/
Log:
the new JON/JOPR/RHQ Teiid Console
15 years, 4 months
teiid SVN: r1206 - in trunk: engine/src/main/java/org/teiid/dqp/internal/process and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-31 00:09:29 -0400 (Fri, 31 Jul 2009)
New Revision: 1206
Modified:
trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/runtime/src/test/resources/jboss-cache-configuration.xml
Log:
TEIID-485 updating the integration version of the cache config and calling stop prior to destroy
Modified: trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java
===================================================================
--- trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java 2009-07-30 16:53:28 UTC (rev 1205)
+++ trunk/cache-jbosscache/src/main/java/com/metamatrix/cache/jboss/JBossCacheFactory.java 2009-07-31 04:09:29 UTC (rev 1206)
@@ -111,6 +111,7 @@
public void destroy() {
jmxManager.unregisterAllMBeans();
+ this.cacheStore.stop();
this.cacheStore.destroy();
this.destroyed = true;
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-07-30 16:53:28 UTC (rev 1205)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2009-07-31 04:09:29 UTC (rev 1206)
@@ -161,6 +161,7 @@
*/
@Override
public void stop() throws ApplicationLifecycleException {
+ LogManager.logDetail(LogConstants.CTX_DQP, "Stopping the DQP"); //$NON-NLS-1$
processWorkerPool.shutdownNow();
try {
processWorkerPool.awaitTermination(10, TimeUnit.SECONDS);
Modified: trunk/runtime/src/test/resources/jboss-cache-configuration.xml
===================================================================
--- trunk/runtime/src/test/resources/jboss-cache-configuration.xml 2009-07-30 16:53:28 UTC (rev 1205)
+++ trunk/runtime/src/test/resources/jboss-cache-configuration.xml 2009-07-31 04:09:29 UTC (rev 1206)
@@ -1,72 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
-<server>
- <mbean code="org.jboss.cache.pojo.jmx.CacheJmxWrapper" name="jboss.cache:service=TeiidCache">
- <attribute name="TransactionManagerLookupClass">org.jboss.cache.transaction.GenericTransactionManagerLookup</attribute>
- <attribute name="IsolationLevel">READ_COMMITTED</attribute>
- <attribute name="LockParentForChildInsertRemove">true</attribute>
-
- <attribute name="CacheMode">LOCAL</attribute>
- <attribute name="UseLazyDeserialization">true</attribute>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1">
- <!--
- The max amount of time (in milliseconds) we wait until the
- initial state (ie. the contents of the cache) are retrieved from
- existing members in a clustered environment
- -->
- <attribute name="StateRetrievalTimeout">20000</attribute>
-
- <!--
- Number of milliseconds to wait until all responses for a
- synchronous call have been received.
- -->
- <attribute name="SyncReplTimeout">20000</attribute>
-
- <!-- Max number of milliseconds to wait for a lock acquisition -->
- <attribute name="LockAcquisitionTimeout">15000</attribute>
-
- <!-- Shutdown hook behavior. Valid choices are: DEFAULT, REGISTER and DONT_REGISTER. this element is omitted, DEFAULT is used. -->
- <attribute name="ShutdownHookBehavior">DEFAULT</attribute>
+ <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="15000" lockParentForChildInsertRemove="true" />
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" />
+
+ <shutdown hookBehavior="DEFAULT" />
+
+ <loaders passivation="false" shared="false">
+ <loader class="org.jboss.cache.loader.FileCacheLoader" fetchPersistentState="true" purgeOnStartup="true">
+ <properties>location=./target/scratch/teiid</properties>
+ </loader>
+ </loaders>
+
+ <eviction wakeUpInterval="3000">
+ <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" eventQueueSize="100000">
+ <property name="maxNodes" value="10000" />
+ <!-- 0 = immediate eviction, -1 = no limit -->
+ <property name="timeToLive" value="-1" />
+ </default>
+ </eviction>
- <attribute name="FetchInMemoryState">true</attribute>
-
- <attribute name="CacheLoaderConfig" replace="false">
- <config>
-
- <!-- are the cache loaders shared in a cluster? -->
- <shared>false</shared>
- <!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
- <passivation>true</passivation>
-
- <cacheloader>
- <class>org.jboss.cache.loader.FileCacheLoader</class>
- <properties>location=./target/scratch/teiid</properties>
-
- <!--fetch the persistent state of a cache when joining a cluster-->
- <fetchPersistentState>true</fetchPersistentState>
-
- <!-- empties the specified cache loader when cache loader starts up -->
- <purgeOnStartup>true</purgeOnStartup>
-
- <!-- cache loader is shared among different cache instances -->
- <shared>false</shared>
- </cacheloader>
- </config>
- </attribute>
-
- <attribute name="EvictionPolicyConfig">
- <config>
- <attribute name="wakeUpIntervalSeconds">3</attribute>
- <!-- This defaults to 200000 if not specified -->
- <attribute name="eventQueueSize">100000</attribute>
- <!-- Name of the DEFAULT eviction policy class. -->
- <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
- <!-- Cache wide default -->
- <region name="/_default_">
- <attribute name="maxNodes">10000</attribute>
- <attribute name="timeToLiveSeconds">0</attribute>
- </region>
- </config>
- </attribute>
-
- </mbean>
-</server>
\ No newline at end of file
+ <serialization useLazyDeserialization="true"/>
+
+</jbosscache>
+
\ No newline at end of file
15 years, 4 months
teiid SVN: r1205 - in trunk: connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-30 12:53:28 -0400 (Thu, 30 Jul 2009)
New Revision: 1205
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BindValueVisitor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java
trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
Log:
TEIID-700 fix for oracle bug in union order by with a nested limit. also adding logging to the metadata import
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-07-29 14:26:05 UTC (rev 1204)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-07-30 16:53:28 UTC (rev 1205)
@@ -326,7 +326,7 @@
xaConn = xaDs.getXAConnection();
conn = xaConn.getConnection();
}
- JDBCMetdataProcessor metadataProcessor = new JDBCMetdataProcessor();
+ JDBCMetdataProcessor metadataProcessor = new JDBCMetdataProcessor(this.logger);
PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getImportProperties(), "importer"); //$NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, this.environment.getProperties(), "importer"); //$NON-NLS-1$
metadataProcessor.getConnectorMetadata(conn, metadataFactory);
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java 2009-07-29 14:26:05 UTC (rev 1204)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java 2009-07-30 16:53:28 UTC (rev 1205)
@@ -32,6 +32,7 @@
import java.util.TreeMap;
import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ConnectorLogger;
import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.metadata.runtime.AbstractMetadataRecord;
import org.teiid.connector.metadata.runtime.BaseColumn;
@@ -75,6 +76,12 @@
private boolean importApproximateIndexes = true;
private boolean importProcedures = true;
+ private ConnectorLogger logger;
+
+ public JDBCMetdataProcessor(ConnectorLogger logger) {
+ this.logger = logger;
+ }
+
public void getConnectorMetadata(Connection conn, MetadataFactory metadataFactory)
throws SQLException, ConnectorException {
DatabaseMetaData metadata = conn.getMetaData();
@@ -98,6 +105,7 @@
private void getProcedures(MetadataFactory metadataFactory,
DatabaseMetaData metadata) throws SQLException, ConnectorException {
+ logger.logDetail("JDBCMetadataProcessor - Importing procedures"); //$NON-NLS-1$
ResultSet procedures = metadata.getProcedures(catalog, schemaPattern, procedureNamePattern);
while (procedures.next()) {
String procedureCatalog = procedures.getString(1);
@@ -152,6 +160,7 @@
private Map<String, TableInfo> getTables(MetadataFactory metadataFactory,
DatabaseMetaData metadata) throws SQLException, ConnectorException {
+ logger.logDetail("JDBCMetadataProcessor - Importing tables"); //$NON-NLS-1$
ResultSet tables = metadata.getTables(catalog, schemaPattern, tableNamePattern, tableTypes);
Map<String, TableInfo> tableMap = new HashMap<String, TableInfo>();
while (tables.next()) {
@@ -177,6 +186,7 @@
private void getColumns(MetadataFactory metadataFactory,
DatabaseMetaData metadata, Map<String, TableInfo> tableMap)
throws SQLException, ConnectorException {
+ logger.logDetail("JDBCMetadataProcessor - Importing columns"); //$NON-NLS-1$
ResultSet columns = metadata.getColumns(catalog, schemaPattern, tableNamePattern, null);
int rsColumns = columns.getMetaData().getColumnCount();
while (columns.next()) {
@@ -208,9 +218,10 @@
columns.close();
}
- private static void getPrimaryKeys(MetadataFactory metadataFactory,
+ private void getPrimaryKeys(MetadataFactory metadataFactory,
DatabaseMetaData metadata, Map<String, TableInfo> tableMap)
throws SQLException, ConnectorException {
+ logger.logDetail("JDBCMetadataProcessor - Importing primary keys"); //$NON-NLS-1$
for (TableInfo tableInfo : tableMap.values()) {
ResultSet pks = metadata.getPrimaryKeys(tableInfo.catalog, tableInfo.schema, tableInfo.name);
TreeMap<Short, String> keyColumns = null;
@@ -238,6 +249,7 @@
private void getForeignKeys(MetadataFactory metadataFactory,
DatabaseMetaData metadata, Map<String, TableInfo> tableMap) throws SQLException, ConnectorException {
+ logger.logDetail("JDBCMetadataProcessor - Importing foreign keys"); //$NON-NLS-1$
for (TableInfo tableInfo : tableMap.values()) {
ResultSet fks = metadata.getImportedKeys(tableInfo.catalog, tableInfo.schema, tableInfo.name);
TreeMap<Short, String> keyColumns = null;
@@ -280,6 +292,7 @@
private void getIndexes(MetadataFactory metadataFactory,
DatabaseMetaData metadata, Map<String, TableInfo> tableMap) throws SQLException, ConnectorException {
+ logger.logDetail("JDBCMetadataProcessor - Importing index info"); //$NON-NLS-1$
for (TableInfo tableInfo : tableMap.values()) {
ResultSet indexInfo = metadata.getIndexInfo(tableInfo.catalog, tableInfo.schema, tableInfo.name, false, importApproximateIndexes);
TreeMap<Short, String> indexColumns = null;
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-07-29 14:26:05 UTC (rev 1204)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2009-07-30 16:53:28 UTC (rev 1205)
@@ -49,6 +49,7 @@
import org.teiid.connector.language.IInsertExpressionValueSource;
import org.teiid.connector.language.ILimit;
import org.teiid.connector.language.IQueryCommand;
+import org.teiid.connector.language.ISelectSymbol;
import org.teiid.connector.language.ISetQuery.Operation;
import org.teiid.connector.metadata.runtime.Element;
import org.teiid.connector.visitor.util.SQLReservedWords;
@@ -166,10 +167,34 @@
ILimit limit = queryCommand.getLimit();
queryCommand.setLimit(null);
List<Object> parts = new ArrayList<Object>();
+ parts.add("SELECT "); //$NON-NLS-1$
+ /*
+ * if all of the columns are aliased, assume that names matter - it actually only seems to matter for
+ * the first query of a set op when there is a order by. Rather than adding logic to traverse up,
+ * we just use the projected names
+ */
+ boolean allAliased = true;
+ for (ISelectSymbol selectSymbol : queryCommand.getProjectedQuery().getSelect().getSelectSymbols()) {
+ if (!selectSymbol.hasAlias()) {
+ allAliased = false;
+ break;
+ }
+ }
+ if (allAliased) {
+ String[] columnNames = queryCommand.getColumnNames();
+ for (int i = 0; i < columnNames.length; i++) {
+ if (i > 0) {
+ parts.add(", "); //$NON-NLS-1$
+ }
+ parts.add(columnNames[i]);
+ }
+ } else {
+ parts.add("*"); //$NON-NLS-1$
+ }
if (limit.getRowOffset() > 0) {
- parts.add("SELECT * FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM ("); //$NON-NLS-1$
+ parts.add(" FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM ("); //$NON-NLS-1$
} else {
- parts.add("SELECT * FROM ("); //$NON-NLS-1$
+ parts.add(" FROM ("); //$NON-NLS-1$
}
parts.add(queryCommand);
if (limit.getRowOffset() > 0) {
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BindValueVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BindValueVisitor.java 2009-07-29 14:26:05 UTC (rev 1204)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/BindValueVisitor.java 2009-07-30 16:53:28 UTC (rev 1205)
@@ -27,7 +27,6 @@
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.IInCriteria;
import org.teiid.connector.language.IInlineView;
-import org.teiid.connector.language.IInsert;
import org.teiid.connector.language.IInsertExpressionValueSource;
import org.teiid.connector.language.ILanguageObject;
import org.teiid.connector.language.ILikeCriteria;
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java 2009-07-29 14:26:05 UTC (rev 1204)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/DropFunctionModifier.java 2009-07-30 16:53:28 UTC (rev 1205)
@@ -34,7 +34,7 @@
* can be overridden. This modifier should only be used with functions having the
* minimum or more number of arguments.
*/
-public class DropFunctionModifier extends BasicFunctionModifier implements FunctionModifier {
+public class DropFunctionModifier extends BasicFunctionModifier {
private int replaceIndex = 0;
Modified: trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-07-29 14:26:05 UTC (rev 1204)
+++ trunk/test-integration/src/test/java/com/metamatrix/connector/jdbc/oracle/TestOracleSQLConversionVisitor.java 2009-07-30 16:53:28 UTC (rev 1205)
@@ -457,8 +457,8 @@
}
@Test public void testLimitWithNestedInlineView() throws Exception {
- String input = "select max(intkey), stringkey from (select intkey, stringkey from bqt1.smalla order by intkey limit 100) x group by intkey"; //$NON-NLS-1$
- String output = "SELECT MAX(x.intkey), x.stringkey FROM (SELECT * FROM (SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY intkey) WHERE ROWNUM <= 100) x GROUP BY x.intkey"; //$NON-NLS-1$
+ String input = "select max(intkey), stringkey from (select intkey, stringkey from bqt1.smalla order by intkey limit 100) x group by stringkey"; //$NON-NLS-1$
+ String output = "SELECT MAX(x.intkey), x.stringkey FROM (SELECT * FROM (SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY intkey) WHERE ROWNUM <= 100) x GROUP BY x.stringkey"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(),
input,
@@ -496,6 +496,15 @@
String sql = "select stringnum || '1' from BQT1.Smalla"; //$NON-NLS-1$
String expected = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE concat(SmallA.StringNum, '1') END FROM SmallA"; //$NON-NLS-1$
helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
+ }
+
+ @Test public void testRowLimitWithUnionOrderBy() throws Exception {
+ String input = "(select intkey from bqt1.smalla limit 50, 100) union select intnum from bqt1.smalla order by intkey"; //$NON-NLS-1$
+ String output = "SELECT c_0 FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT g_1.IntKey AS c_0 FROM SmallA g_1) VIEW_FOR_LIMIT WHERE ROWNUM <= 150) WHERE ROWNUM_ > 50 UNION SELECT g_0.IntNum AS c_0 FROM SmallA g_0 ORDER BY c_0"; //$NON-NLS-1$
+
+ CommandBuilder commandBuilder = new CommandBuilder(FakeMetadataFactory.exampleBQTCached());
+ ICommand obj = commandBuilder.getCommand(input, true, true);
+ this.helpTestVisitor(obj, EMPTY_CONTEXT, null, output);
}
}
15 years, 4 months
teiid SVN: r1204 - trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-07-29 10:26:05 -0400 (Wed, 29 Jul 2009)
New Revision: 1204
Modified:
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/PartialResultsWarning.java
Log:
TEIID-474: adding serial version id for all the client side classes that implement serializable interface
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/PartialResultsWarning.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/PartialResultsWarning.java 2009-07-28 23:09:48 UTC (rev 1203)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/PartialResultsWarning.java 2009-07-29 14:26:05 UTC (rev 1204)
@@ -38,7 +38,8 @@
*/
public class PartialResultsWarning extends SQLWarning {
- private Map failures;
+ private static final long serialVersionUID = 5301215068719177369L;
+ private Map failures;
/**
* Construct partial results warning.
15 years, 4 months