You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2012/09/23 20:01:54 UTC

svn commit: r1389109 [2/6] - in /incubator/ambari/branches/AMBARI-666: ./ ambari-api/ ambari-api/src/ ambari-api/src/main/ ambari-api/src/main/java/ ambari-api/src/main/java/org/ ambari-api/src/main/java/org/apache/ ambari-api/src/main/java/org/apache/...

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/Comparables.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/Comparables.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/Comparables.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/Comparables.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.controller.predicate;
+
+/**
+ *
+ */
+public class Comparables {
+
+  public static Comparable<String> forInteger(final Integer value) {
+
+    return new Comparable<String>() {
+      @Override
+      public int compareTo(String s) {
+        return value.compareTo(Integer.valueOf(s));
+      }
+    };
+  }
+
+  public static Comparable<String> forFloat(final Float value) {
+
+    return new Comparable<String>() {
+      @Override
+      public int compareTo(String s) {
+        return value.compareTo(Float.valueOf(s));
+      }
+    };
+  }
+
+  public static Comparable<String> forDouble(final Double value) {
+
+    return new Comparable<String>() {
+      @Override
+      public int compareTo(String s) {
+        return value.compareTo(Double.valueOf(s));
+      }
+    };
+  }
+
+  public static Comparable<String> forLong(final Long value) {
+
+    return new Comparable<String>() {
+      @Override
+      public int compareTo(String s) {
+        return value.compareTo(Long.valueOf(s));
+      }
+    };
+  }
+
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/ComparisonPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/ComparisonPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/ComparisonPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/ComparisonPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+
+/**
+ * Predicate that compares a given value to a {@link Resource} property.
+ */
+public abstract class ComparisonPredicate extends PropertyPredicate implements BasePredicate {
+  private final Comparable<String> value;
+
+  public ComparisonPredicate(PropertyId propertyId, Comparable<String> value) {
+    super(propertyId);
+    this.value = value;
+  }
+
+  public Comparable<String> getValue() {
+    return value;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof ComparisonPredicate)) return false;
+    if (!super.equals(o)) return false;
+
+    ComparisonPredicate that = (ComparisonPredicate) o;
+
+    if (value != null ? !value.equals(that.value) : that.value != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = super.hashCode();
+    result = 31 * result + (value != null ? value.hashCode() : 0);
+    return result;
+  }
+
+  @Override
+  public void accept(PredicateVisitor visitor) {
+    visitor.acceptComparisonPredicate(this);
+  }
+
+
+  public abstract String getOperator();
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/EqualsPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/EqualsPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/EqualsPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/EqualsPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+
+/**
+ * Predicate that checks equality of a given value to a {@link Resource} property.
+ */
+public class EqualsPredicate extends ComparisonPredicate {
+
+
+  public EqualsPredicate(PropertyId propertyId, Comparable<String> value) {
+    super(propertyId, value);
+  }
+
+  @Override
+  public boolean evaluate(Resource resource) {
+    return getValue().compareTo(resource.getPropertyValue(getPropertyId())) == 0;
+  }
+
+  @Override
+  public String getOperator() {
+    return "=";
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+
+/**
+ * Predicate that checks if a given value is greater than or equal to a {@link Resource} property.
+ */
+public class GreaterEqualsPredicate extends ComparisonPredicate {
+
+  public GreaterEqualsPredicate(PropertyId propertyId, Comparable<String> value) {
+    super(propertyId, value);
+  }
+
+  @Override
+  public boolean evaluate(Resource resource) {
+    return getValue().compareTo(resource.getPropertyValue(getPropertyId())) <= 0;
+  }
+
+  @Override
+  public String getOperator() {
+    return ">=";
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/GreaterPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+
+/**
+ * Predicate that checks if a given value is greater than a {@link Resource} property.
+ */
+public class GreaterPredicate extends ComparisonPredicate {
+
+  public GreaterPredicate(PropertyId propertyId, Comparable<String> value) {
+    super(propertyId, value);
+  }
+
+  @Override
+  public boolean evaluate(Resource resource) {
+    return getValue().compareTo(resource.getPropertyValue(getPropertyId())) < 0;
+  }
+
+  @Override
+  public String getOperator() {
+    return ">";
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+
+
+/**
+ * Predicate that checks if a given value is less than or equal to a {@link Resource} property.
+ */
+public class LessEqualsPredicate extends ComparisonPredicate {
+
+  public LessEqualsPredicate(PropertyId propertyId, Comparable<String> value) {
+    super(propertyId, value);
+  }
+
+  @Override
+  public boolean evaluate(Resource resource) {
+    return getValue().compareTo(resource.getPropertyValue(getPropertyId())) >= 0;
+  }
+
+  @Override
+  public String getOperator() {
+    return "<=";
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/LessPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+
+/**
+ * Predicate that checks if a given value is less than a {@link Resource} property.
+ */
+public class LessPredicate extends ComparisonPredicate {
+
+  public LessPredicate(PropertyId propertyId, Comparable<String> value) {
+    super(propertyId, value);
+  }
+
+  @Override
+  public boolean evaluate(Resource resource) {
+    return getValue().compareTo(resource.getPropertyValue(getPropertyId())) > 0;
+  }
+
+  @Override
+  public String getOperator() {
+    return "<";
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/NotPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/NotPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/NotPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/NotPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.Resource;
+
+/**
+ * Predicate that negates the evaluation of another predicate.
+ */
+public class NotPredicate extends UnaryPredicate {
+
+  public NotPredicate(BasePredicate predicate) {
+    super(predicate);
+  }
+
+  @Override
+  public boolean evaluate(Resource resource) {
+    return !getPredicate().evaluate(resource);
+  }
+
+  @Override
+  public String getOperator() {
+    return "NOT";
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/OrPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/OrPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/OrPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/OrPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.Resource;
+
+/**
+ * Predicate which evaluates to true if any of the predicates in a predicate
+ * array evaluate to true.
+ */
+public class OrPredicate extends ArrayPredicate {
+
+  public OrPredicate(BasePredicate... predicates) {
+    super(predicates);
+  }
+
+  @Override
+  public boolean evaluate(Resource resource) {
+    BasePredicate[] predicates = getPredicates();
+    for (BasePredicate predicate : predicates) {
+      if (predicate.evaluate(resource)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  @Override
+  public String getOperator() {
+    return "OR";
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitor.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitor.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitor.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+/**
+ * A visitor of predicates.
+ */
+public interface PredicateVisitor {
+
+  public void acceptComparisonPredicate(ComparisonPredicate predicate);
+
+  public void acceptArrayPredicate(ArrayPredicate predicate);
+
+  public void acceptUnaryPredicate(UnaryPredicate predicate);
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitorAcceptor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitorAcceptor.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitorAcceptor.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PredicateVisitorAcceptor.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+/**
+ * An acceptor of predicate visitors.
+ */
+public interface PredicateVisitorAcceptor {
+
+  public void accept(PredicateVisitor visitor);
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PropertyPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PropertyPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PropertyPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/PropertyPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Predicate that is associated with a resource property.
+ */
+public abstract class PropertyPredicate implements BasePredicate {
+  private final PropertyId propertyId;
+
+  public PropertyPredicate(PropertyId propertyId) {
+    this.propertyId = propertyId;
+  }
+
+  @Override
+  public Set<PropertyId> getPropertyIds() {
+    return Collections.singleton(propertyId);
+  }
+
+  public PropertyId getPropertyId() {
+    return propertyId;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+
+    if (this == o) {
+      return true;
+    }
+
+    if (!(o instanceof PropertyPredicate)) {
+      return false;
+    }
+
+    PropertyPredicate that = (PropertyPredicate) o;
+
+    return propertyId == null ? that.propertyId == null : propertyId.equals(that.propertyId);
+  }
+
+  @Override
+  public int hashCode() {
+    return propertyId != null ? propertyId.hashCode() : 0;
+  }
+}
+

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/UnaryPredicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/UnaryPredicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/UnaryPredicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/predicate/UnaryPredicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.predicate;
+
+import org.apache.ambari.api.controller.spi.PropertyId;
+
+import java.util.Set;
+
+/**
+ * Predicate that operates on one other predicate.
+ */
+public abstract class UnaryPredicate implements BasePredicate {
+  private final BasePredicate predicate;
+
+  public UnaryPredicate(BasePredicate predicate) {
+    this.predicate = predicate;
+  }
+
+  public BasePredicate getPredicate() {
+    return predicate;
+  }
+
+  @Override
+  public Set<PropertyId> getPropertyIds() {
+    return predicate.getPropertyIds();
+  }
+
+  @Override
+  public void accept(PredicateVisitor visitor) {
+    visitor.acceptUnaryPredicate(this);
+  }
+
+  public abstract String getOperator();
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ClusterController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ClusterController.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ClusterController.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ClusterController.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+import java.util.Set;
+
+/**
+ * The cluster controller is the main access point for getting properties
+ * from the backend providers.  A cluster controller maintains a mapping of
+ * resource providers keyed by resource types.
+ */
+public interface ClusterController {
+
+  // ----- Monitoring ------------------------------------------------------
+
+  /**
+   * Get the resources of the given type filtered by the given request and
+   * predicate objects.
+   *
+   * @param type      the type of the requested resources
+   * @param request   the request object which defines the desired set of properties
+   * @param predicate the predicate object which filters which resources are returned
+   * @return an iterable object of the requested resources
+   */
+  public Iterable<Resource> getResources(Resource.Type type, Request request, Predicate predicate);
+
+  /**
+   * Get the {@link Schema schema} for the given resource type.  The schema
+   * for a given resource type describes the properties and categories provided
+   * by that type of resource.
+   *
+   * @param type the resource type
+   * @return the schema object for the given resource
+   */
+  public Schema getSchema(Resource.Type type);
+
+  // ----- Management -------------------------------------------------------
+  // TODO
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Predicate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Predicate.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Predicate.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Predicate.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+/**
+ * The predicate is used to filter the resources returned from the cluster
+ * controller.  The predicate can examine a resource object and determine
+ * whether or not it should be included in the returned results.
+ */
+public interface Predicate {
+  /**
+   * Evaluate the predicate for the given resource.
+   *
+   * @param resource the resource to evaluate the predicate against
+   * @return the result of applying the predicate to the given resource
+   */
+  public boolean evaluate(Resource resource);
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyId.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyId.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyId.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyId.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+/**
+ * The property id is used to uniquely identify a resource property.  The
+ * property id is a composite of property name and category name as
+ * well as an indicator for temporal values.
+ */
+public interface PropertyId {
+
+  /**
+   * Get the property name.
+   *
+   * @return the property name
+   */
+  public String getName();
+
+  /**
+   * Get the category name.
+   *
+   * @return the category name
+   */
+  public String getCategory();
+
+  /**
+   * Indicates whether or not this property provides a temporal value.
+   *
+   * @return true if this property provides a temporal value.
+   */
+  public boolean isTemporal();
+
+  @Override
+  public int hashCode();
+
+  @Override
+  public boolean equals(Object o);
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyProvider.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyProvider.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/PropertyProvider.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+import java.util.Set;
+
+/**
+ * The property provider is used to plug in various property sources into a
+ * resource provider.  The property provider is able to populate, or partially
+ * populate a given resource object with property values.
+ */
+public interface PropertyProvider {
+
+  /**
+   * Populate the given set of resource with any properties that this property
+   * provider can provide and return a populated set of resources.  The provider
+   * may drop resources from the original set if it determines that the don't
+   * meet the conditions of the predicate.
+   *
+   * @param resources  the resources to be populated
+   * @param request    the request object which defines the desired set of properties
+   * @param predicate  the predicate object which filters which resources are returned
+   *
+   * @return the populated set of resources
+   */
+  public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate);
+
+  /**
+   * Get the set of property ids for the properties that this provider can provide.
+   *
+   * @return the set of property ids for the properties that this provider can provide
+   */
+  public Set<PropertyId> getPropertyIds();
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Request.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Request.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Request.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Request.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+import java.util.Set;
+
+/**
+ * The request object contains the property ids of all the properties
+ * that are wanted for the query.  The request object also contains any
+ * temporal (date range) information, if any, for each requested property.
+ */
+public interface Request {
+
+  /**
+   * The set of property ids being requested.  An empty set signifies
+   * that all supported properties should be returned (i.e. select * ).
+   *
+   * @return the set of property ids being requested
+   */
+  public Set<PropertyId> getPropertyIds();
+
+  /**
+   * Get the {@link TemporalInfo temporal information} for the given property
+   * id for this request, if any.
+   *
+   * @param id the property id
+   * @return the temporal information for the given property id; null if noe exists
+   */
+  public TemporalInfo getTemporalInfo(PropertyId id);
+
+  /**
+   * Temporal request information describing a range and increment of time.
+   */
+  public static interface TemporalInfo {
+
+    /**
+     * Get the start of the requested time range.  The time is given in
+     * seconds since the Unix epoch.
+     *
+     * @return the start time in seconds
+     */
+    public long getStartTime();
+
+    /**
+     * Get the end of the requested time range.  The time is given in
+     * seconds since the Unix epoch.
+     *
+     * @return the end time in seconds
+     */
+    public long getEndTime();
+
+    /**
+     * Get the requested time between each data point of the temporal
+     * data.  The time is given in seconds.
+     *
+     * @return the step time in seconds
+     */
+    public long getStep();
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Resource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Resource.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Resource.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Resource.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+import java.util.Map;
+
+/**
+ * The resource object represents a requested resource.  The resource
+ * contains a collection of values for the requested properties.
+ */
+public interface Resource {
+  /**
+   * Get the resource type.
+   *
+   * @return the resource type
+   */
+  public Type getType();
+
+  /**
+   * Get the map of categories contained by this resource.  The map
+   * is keyed by the category name and contains maps of properties
+   * for each category.
+   *
+   * @return the map of categories
+   */
+  public Map<String, Map<String, String>> getCategories();
+
+  /**
+   * Set a string property value for the given property id on this resource.
+   *
+   * @param id    the property id
+   * @param value the value
+   */
+  public void setProperty(PropertyId id, String value);
+
+  /**
+   * Set a integer property value for the given property id on this resource.
+   *
+   * @param id    the property id
+   * @param value the value
+   */
+  public void setProperty(PropertyId id, Integer value);
+
+  /**
+   * Set a float property value for the given property id on this resource.
+   *
+   * @param id    the property id
+   * @param value the value
+   */
+  public void setProperty(PropertyId id, Float value);
+
+  /**
+   * Set a double property value for the given property id on this resource.
+   *
+   * @param id    the property id
+   * @param value the value
+   */
+  public void setProperty(PropertyId id, Double value);
+
+  /**
+   * Set a long property value for the given property id on this resource.
+   *
+   * @param id    the property id
+   * @param value the value
+   */
+  public void setProperty(PropertyId id, Long value);
+
+  /**
+   * Get a property value for the given property id from this resource.
+   *
+   * @param id the property id
+   * @return the property value
+   */
+  public String getPropertyValue(PropertyId id);
+
+  /**
+   * Resource types.
+   */
+  public enum Type {
+    Cluster,
+    Service,
+    Host,
+    Component,
+    HostComponent
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ResourceProvider.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ResourceProvider.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ResourceProvider.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+import java.util.Set;
+
+/**
+ * The resource provider allows for the plugging in of a back end data store
+ * for a resource type.  The resource provider is associated with a specific
+ * resource type and can be queried for a list of resources of that type.
+ * The resource provider plugs into and is used by the
+ * {@link ClusterController cluster controller} to obtain a list of resources
+ * for a given request.
+ */
+public interface ResourceProvider {
+  /**
+   * Get a set of {@link Resource resources} based on the given request and predicate
+   * information.
+   * </p>
+   * Note that it is not required for this resource provider to completely filter
+   * the set of resources based on the given predicate.  It may not be possible
+   * since some of the properties involved may be provided by another
+   * {@link PropertyProvider provider}.  This partial filtering is allowed because
+   * the predicate will always be applied by the calling cluster controller.  The
+   * predicate is made available at this level so that some pre-filtering can be done
+   * as an optimization.
+   * </p>
+   * A simple implementation of a resource provider may choose to just return all of
+   * the resources of a given type and allow the calling cluster controller to filter
+   * based on the predicate.
+   *
+   * @param request   the request object which defines the desired set of properties
+   * @param predicate the predicate object which can be used to filter which
+   *                  resources are returned
+   * @return a set of resources based on the given request and predicate information
+   */
+  public Set<Resource> getResources(Request request, Predicate predicate);
+
+  /**
+   * Get the set of property ids for the properties that this provider can provide.
+   *
+   * @return the set of property ids for the properties that this provider can provide
+   */
+  public Set<PropertyId> getPropertyIds();
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Schema.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Schema.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Schema.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Schema.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.spi;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * The schema is used to describe all of the properties that a resource type
+ * supports.
+ */
+public interface Schema {
+
+  /**
+   * Get the property id for the property that uniquely identifies
+   * the given resource type for the resource described by this schema.
+   * </p>
+   * For example, the resource 'HostComponent' is uniquely identified by
+   * its associated 'Cluster', 'Host' and 'Component' resources.  Passing
+   * the 'Host' resource type to
+   * {@link Schema#getKeyPropertyId(org.apache.ambari.api.controller.spi.Resource.Type)}
+   * on a schema object of a 'HostComponent' resource will return the id of the
+   * property of the foreign key reference from the 'HostComponent' to the 'Host'.
+   *
+   * @param type the resource type
+   * @return the key property id for the given resource type
+   */
+  public PropertyId getKeyPropertyId(Resource.Type type);
+
+  /**
+   * Get the map of categories for this schema's resource.  The map
+   * is keyed by the category name and contains sets of property ids
+   * for each category.
+   *
+   * @return the map of categories
+   */
+  public Map<String, Set<String>> getCategories();
+
+  /**
+   * Get the resource provider for the resource type associated with this schema.
+   *
+   * @return the resource provider for the resource type associated with this schema
+   */
+  public ResourceProvider getResourceProvider();
+
+  /**
+   * Get the list of property providers for the resource associated with this schema.
+   *
+   * @return the list of property providers for the resource associated with this schema
+   */
+  public List<PropertyProvider> getPropertyProviders();
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/ClusterControllerHelper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/ClusterControllerHelper.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/ClusterControllerHelper.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/ClusterControllerHelper.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.controller.utilities;
+
+import org.apache.ambari.api.controller.internal.ClusterControllerImpl;
+import org.apache.ambari.api.controller.internal.SchemaImpl;
+import org.apache.ambari.api.controller.jdbc.ConnectionFactory;
+import org.apache.ambari.api.controller.jdbc.JDBCResourceProvider;
+import org.apache.ambari.api.controller.jdbc.SQLiteConnectionFactory;
+import org.apache.ambari.api.controller.spi.ClusterController;
+import org.apache.ambari.api.controller.spi.PropertyProvider;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.apache.ambari.api.controller.spi.ResourceProvider;
+import org.apache.ambari.api.controller.spi.Schema;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Temporary class to bootstrap a cluster controller.  TODO : Replace this global state with injection.
+ */
+public class ClusterControllerHelper {
+  private static ClusterController controller;
+
+  public static final ConnectionFactory CONNECTION_FACTORY = new SQLiteConnectionFactory();
+
+
+  public static synchronized ClusterController getClusterController() {
+
+    if (controller == null) {
+      controller = new ClusterControllerImpl(getResourceSchemas());
+    }
+    return controller;
+  }
+
+  private static Map<Resource.Type, Schema> getResourceSchemas() {
+    Map<Resource.Type, Schema> schemas = new HashMap<Resource.Type, Schema>();
+
+    schemas.put(Resource.Type.Cluster, getResourceSchema(Resource.Type.Cluster));
+
+    return schemas;
+  }
+
+  private static Schema getResourceSchema(Resource.Type type) {
+
+    ResourceProvider resourceProvider =  JDBCResourceProvider.create(CONNECTION_FACTORY, type);
+    List<PropertyProvider> propertyProviders = new LinkedList<PropertyProvider>();
+
+    return new SchemaImpl(type, resourceProvider, propertyProviders, Properties.getKeyPropertyIds(type));
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/DBHelper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/DBHelper.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/DBHelper.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/DBHelper.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.utilities;
+
+import org.apache.ambari.api.controller.jdbc.ConnectionFactory;
+import org.apache.ambari.api.controller.jdbc.SQLiteConnectionFactory;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class DBHelper {
+
+  public static final ConnectionFactory CONNECTION_FACTORY = new SQLiteConnectionFactory();
+
+  private static final Map<String, String> HOSTS = readHosts();
+
+  public static Map<String, String> getHosts() {
+    return HOSTS;
+  }
+
+  private static Map<String, String> readHosts() {
+    Map<String, String> hosts = new HashMap<String, String>();
+
+    try {
+      Connection connection = CONNECTION_FACTORY.getConnection();
+
+      try {
+        String sql = "select attributes from hosts";
+
+        Statement statement = connection.createStatement();
+        statement.setQueryTimeout(30);  // set timeout to 30 sec.
+
+        ResultSet rs = statement.executeQuery(sql);
+
+        ObjectMapper mapper = new ObjectMapper();
+
+        while (rs.next()) {
+          String attributes = rs.getString(1);
+
+          if (!attributes.startsWith("[]")) {
+            try {
+              Map<String, String> attributeMap = mapper.readValue(attributes, new TypeReference<Map<String, String>>() {
+              });
+              hosts.put(attributeMap.get("privateFQDN"), attributeMap.get("publicFQDN"));
+            } catch (IOException e) {
+              throw new IllegalStateException("Can't read hosts " + attributes, e);
+            }
+          }
+        }
+
+      } finally {
+        connection.close();
+      }
+
+    } catch (SQLException e) {
+      throw new IllegalStateException("Can't access DB.", e);
+    }
+
+    System.out.println(hosts);
+
+    return hosts;
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/HostNames.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/HostNames.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/HostNames.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/HostNames.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.utilities;
+
+/**
+ *
+ */
+public class HostNames {
+
+
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateBuilder.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateBuilder.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateBuilder.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateBuilder.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,315 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.utilities;
+
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.predicate.AndPredicate;
+import org.apache.ambari.api.controller.predicate.BasePredicate;
+import org.apache.ambari.api.controller.predicate.Comparables;
+import org.apache.ambari.api.controller.predicate.EqualsPredicate;
+import org.apache.ambari.api.controller.predicate.GreaterEqualsPredicate;
+import org.apache.ambari.api.controller.predicate.GreaterPredicate;
+import org.apache.ambari.api.controller.predicate.LessEqualsPredicate;
+import org.apache.ambari.api.controller.predicate.LessPredicate;
+import org.apache.ambari.api.controller.predicate.NotPredicate;
+import org.apache.ambari.api.controller.predicate.OrPredicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Builder for predicates.
+ */
+public class PredicateBuilder {
+
+  private PropertyId propertyId;
+  private List<BasePredicate> predicates = new LinkedList<BasePredicate>();
+  private Operator operator = null;
+  private final PredicateBuilder outer;
+  private boolean done = false;
+  private boolean not = false;
+
+  public PredicateBuilder() {
+    this.outer = null;
+  }
+
+  private PredicateBuilder(PredicateBuilder outer) {
+    this.outer = outer;
+  }
+
+  private enum Operator {
+    And,
+    Or
+  }
+
+
+  public PredicateBuilderWithProperty property(String property, String category, boolean temporal) {
+    return property(new PropertyIdImpl(property, category, temporal));
+  }
+
+  public PredicateBuilderWithProperty property(String property, String category) {
+    return property(property, category, false);
+  }
+
+  public PredicateBuilderWithProperty property(String property) {
+    return property(property, null);
+  }
+
+  public PredicateBuilderWithProperty property(PropertyId id) {
+    checkDone();
+    propertyId = id;
+    return new PredicateBuilderWithProperty();
+  }
+
+  public PredicateBuilder not() {
+    not = true;
+    return this;
+  }
+
+
+  public PredicateBuilder begin() {
+    checkDone();
+    return new PredicateBuilder(this);
+  }
+
+  public BasePredicate toPredicate() {
+    return getPredicate();
+  }
+
+  private void checkDone() {
+    if (done) {
+      throw new IllegalStateException("Can't reuse a predicate builder.");
+    }
+  }
+
+  private PredicateBuilderWithPredicate getPredicateBuilderWithPredicate() {
+    return new PredicateBuilderWithPredicate();
+  }
+
+  private void addPredicate(BasePredicate predicate) {
+    predicates.add(predicate);
+  }
+
+  private void handleComparator() {
+    if (operator == null) {
+      return;
+    }
+
+    if (predicates.size() == 0) {
+      throw new IllegalStateException("No left operand.");
+    }
+    BasePredicate predicate;
+
+    switch (operator) {
+      case And:
+        predicate = new AndPredicate(predicates.toArray(new BasePredicate[predicates.size()]));
+        break;
+      case Or:
+        predicate = new OrPredicate(predicates.toArray(new BasePredicate[predicates.size()]));
+        break;
+      default:
+        throw new IllegalStateException("Unknown operator " + this.operator);
+    }
+    predicates.clear();
+    addPredicate(predicate);
+  }
+
+  private BasePredicate getPredicate() {
+    handleComparator();
+
+    if (predicates.size() == 1) {
+      BasePredicate predicate = predicates.get(0);
+      if (not) {
+        predicate = new NotPredicate(predicate);
+        not = false;
+      }
+      return predicate;
+    }
+    throw new IllegalStateException("Can't return a predicate.");
+  }
+
+  public class PredicateBuilderWithProperty {
+
+    // ----- Equals -----
+    public PredicateBuilderWithPredicate equals(Comparable<String> value) {
+      if (propertyId == null) {
+        throw new IllegalStateException("No property.");
+      }
+      addPredicate(new EqualsPredicate(propertyId, value));
+
+      return new PredicateBuilderWithPredicate();
+    }
+
+    public PredicateBuilderWithPredicate equals(Integer value) {
+      return equals(Comparables.forInteger(value));
+    }
+
+    public PredicateBuilderWithPredicate equals(Float value) {
+      return equals(Comparables.forFloat(value));
+    }
+
+    public PredicateBuilderWithPredicate equals(Double value) {
+      return equals(Comparables.forDouble(value));
+    }
+
+    public PredicateBuilderWithPredicate equals(Long value) {
+      return equals(Comparables.forLong(value));
+    }
+
+    // ----- Greater than -----
+    public PredicateBuilderWithPredicate greaterThan(Comparable<String> value) {
+      if (propertyId == null) {
+        throw new IllegalStateException("No property.");
+      }
+      addPredicate(new GreaterPredicate(propertyId, value));
+
+      return new PredicateBuilderWithPredicate();
+    }
+
+    public PredicateBuilderWithPredicate greaterThan(Integer value) {
+      return greaterThan(Comparables.forInteger(value));
+    }
+
+    public PredicateBuilderWithPredicate greaterThan(Float value) {
+      return greaterThan(Comparables.forFloat(value));
+    }
+
+    public PredicateBuilderWithPredicate greaterThan(Double value) {
+      return greaterThan(Comparables.forDouble(value));
+    }
+
+    public PredicateBuilderWithPredicate greaterThan(Long value) {
+      return greaterThan(Comparables.forLong(value));
+    }
+
+    // ----- Greater than equal to -----
+    public PredicateBuilderWithPredicate greaterThanEqualTo(Comparable<String> value) {
+      if (propertyId == null) {
+        throw new IllegalStateException("No property.");
+      }
+      addPredicate(new GreaterEqualsPredicate(propertyId, value));
+
+      return new PredicateBuilderWithPredicate();
+    }
+
+    public PredicateBuilderWithPredicate greaterThanEqualTo(Integer value) {
+      return greaterThanEqualTo(Comparables.forInteger(value));
+    }
+
+    public PredicateBuilderWithPredicate greaterThanEqualTo(Float value) {
+      return greaterThanEqualTo(Comparables.forFloat(value));
+    }
+
+    public PredicateBuilderWithPredicate greaterThanEqualTo(Double value) {
+      return greaterThanEqualTo(Comparables.forDouble(value));
+    }
+
+    public PredicateBuilderWithPredicate greaterThanEqualTo(Long value) {
+      return greaterThanEqualTo(Comparables.forLong(value));
+    }
+
+    // ----- Less than -----
+    public PredicateBuilderWithPredicate lessThan(Comparable<String> value) {
+      if (propertyId == null) {
+        throw new IllegalStateException("No property.");
+      }
+      addPredicate(new LessPredicate(propertyId, value));
+
+      return new PredicateBuilderWithPredicate();
+    }
+
+    public PredicateBuilderWithPredicate lessThan(Integer value) {
+      return lessThan(Comparables.forInteger(value));
+    }
+
+    public PredicateBuilderWithPredicate lessThan(Float value) {
+      return lessThan(Comparables.forFloat(value));
+    }
+
+    public PredicateBuilderWithPredicate lessThan(Double value) {
+      return lessThan(Comparables.forDouble(value));
+    }
+
+    public PredicateBuilderWithPredicate lessThan(Long value) {
+      return lessThan(Comparables.forLong(value));
+    }
+
+    // ----- Less than equal to -----
+    public PredicateBuilderWithPredicate lessThanEqualTo(Comparable<String> value) {
+      if (propertyId == null) {
+        throw new IllegalStateException("No property.");
+      }
+      addPredicate(new LessEqualsPredicate(propertyId, value));
+
+      return new PredicateBuilderWithPredicate();
+    }
+
+    public PredicateBuilderWithPredicate lessThanEqualTo(Integer value) {
+      return lessThanEqualTo(Comparables.forInteger(value));
+    }
+
+    public PredicateBuilderWithPredicate lessThanEqualTo(Float value) {
+      return lessThanEqualTo(Comparables.forFloat(value));
+    }
+
+    public PredicateBuilderWithPredicate lessThanEqualTo(Double value) {
+      return lessThanEqualTo(Comparables.forDouble(value));
+    }
+
+    public PredicateBuilderWithPredicate lessThanEqualTo(Long value) {
+      return lessThanEqualTo(Comparables.forLong(value));
+    }
+  }
+
+  public class PredicateBuilderWithPredicate {
+    public PredicateBuilder and() {
+
+      if (operator != Operator.And) {
+        handleComparator();
+        operator = Operator.And;
+      }
+      return PredicateBuilder.this;
+    }
+
+    public PredicateBuilder or() {
+
+      if (operator != Operator.Or) {
+        handleComparator();
+        operator = Operator.Or;
+      }
+      return PredicateBuilder.this;
+    }
+
+    public BasePredicate toPredicate() {
+      if (outer != null) {
+        throw new IllegalStateException("Unbalanced block - missing end.");
+      }
+      done = true;
+      return getPredicate();
+    }
+
+    public PredicateBuilderWithPredicate end() {
+      if (outer == null) {
+        throw new IllegalStateException("Unbalanced block - missing begin.");
+      }
+      outer.addPredicate(getPredicate());
+      return outer.getPredicateBuilderWithPredicate();
+    }
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateHelper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateHelper.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateHelper.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/PredicateHelper.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.utilities;
+
+import org.apache.ambari.api.controller.predicate.BasePredicate;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ *
+ */
+public class PredicateHelper {
+
+  public static Set<PropertyId> getPropertyIds(Predicate predicate) {
+    if (predicate instanceof BasePredicate) {
+      return ((BasePredicate) predicate).getPropertyIds();
+    }
+    return Collections.emptySet();
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/Properties.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/Properties.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/Properties.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/Properties.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.api.controller.utilities;
+
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public class Properties {
+
+  private static final String PROPERTIES_FILE = "properties.json";
+  private static final String KEY_PROPERTIES_FILE = "key_properties.json";
+
+  private static final Map<String, Map<String, Set<PropertyId>>> PROPERTY_IDS = readPropertyIds(PROPERTIES_FILE);
+  private static final Map<String, Map<String, PropertyId>> KEY_PROPERTY_IDS = readKeyPropertyIds(KEY_PROPERTIES_FILE);
+
+  public static PropertyId getPropertyId(String name, String category) {
+    return new PropertyIdImpl(name, category, false);
+  }
+
+  public static PropertyId getPropertyId(String name, String category, boolean temporal) {
+    return new PropertyIdImpl(name, category, temporal);
+  }
+
+  public static Set<PropertyId> getPropertyIds(Resource.Type resourceType, String providerKey) {
+
+    Map<String, Set<PropertyId>> propertyIds = PROPERTY_IDS.get(resourceType.toString());
+    if (propertyIds != null) {
+      return propertyIds.get(providerKey);
+    }
+    return Collections.emptySet();
+  }
+
+  public static Map<String, PropertyId> getKeyPropertyIds(Resource.Type resourceType) {
+    return KEY_PROPERTY_IDS.get(resourceType.toString());
+  }
+
+  private static Map<String, Map<String, Set<PropertyId>>> readPropertyIds(String filename) {
+    ObjectMapper mapper = new ObjectMapper();
+
+    try {
+      return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<String, Map<String, Set<PropertyIdImpl>>>>() {
+      });
+    } catch (IOException e) {
+      throw new IllegalStateException("Can't read properties file " + filename, e);
+    }
+  }
+
+  private static Map<String, Map<String, PropertyId>> readKeyPropertyIds(String filename) {
+    ObjectMapper mapper = new ObjectMapper();
+
+    try {
+      return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<String, Map<String, PropertyIdImpl>>>() {
+      });
+    } catch (IOException e) {
+      throw new IllegalStateException("Can't read properties file " + filename, e);
+    }
+  }
+
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/DelegatingRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/DelegatingRequestHandler.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/DelegatingRequestHandler.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/DelegatingRequestHandler.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.handlers;
+
+import org.apache.ambari.api.services.Request;
+import org.apache.ambari.api.services.Result;
+
+/**
+ *
+ */
+public class DelegatingRequestHandler implements RequestHandler {
+  @Override
+  public Result handleRequest(Request request) {
+    return getRequestHandlerFactory().getRequestHandler(request.getRequestType()).handleRequest(request);
+  }
+
+  RequestHandlerFactory getRequestHandlerFactory() {
+    return new RequestHandlerFactory();
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/ReadRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/ReadRequestHandler.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/ReadRequestHandler.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/ReadRequestHandler.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.handlers;
+
+import org.apache.ambari.api.services.Request;
+import org.apache.ambari.api.services.Result;
+import org.apache.ambari.api.query.Query;
+
+/**
+ *
+ */
+public class ReadRequestHandler implements RequestHandler {
+
+  @Override
+  public Result handleRequest(Request request) {
+    Query query = request.getResource().getQuery();
+
+    // would need to account for PR and expansion here
+
+    return query.execute();
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandler.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandler.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandler.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.handlers;
+
+import org.apache.ambari.api.services.Request;
+import org.apache.ambari.api.services.Result;
+
+/**
+ *
+ */
+public interface RequestHandler {
+  public Result handleRequest(Request request);
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandlerFactory.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandlerFactory.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/handlers/RequestHandlerFactory.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.handlers;
+
+import org.apache.ambari.api.services.Request;
+
+/**
+ *
+ */
+public class RequestHandlerFactory {
+  public RequestHandler getRequestHandler(Request.RequestType requestType) {
+    switch (requestType) {
+      case GET:
+        return new ReadRequestHandler();
+      default:
+        //todo:
+        throw new UnsupportedOperationException("Only GET requests are supported at this time");
+    }
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/Query.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/Query.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/Query.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/Query.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.api.query;
+
+import org.apache.ambari.api.services.Result;
+import org.apache.ambari.api.controller.spi.PropertyId;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public interface Query {
+  public void addAllProperties(Map<String, Set<String>> setProperties);
+
+  public void addProperty(String path, String property);
+
+  public void addProperty(PropertyId property);
+
+  //todo: signature - need path
+  public void retainAllProperties(Set<String> setFields);
+
+  public void clearAllProperties();
+
+  public Result execute();
+}