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 [4/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/services/formatters/HostComponentInstanceFormatter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/HostComponentInstanceFormatter.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/HostComponentInstanceFormatter.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/HostComponentInstanceFormatter.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,94 @@
+/**
+ * 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.services.formatters;
+
+import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.services.Result;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.apache.ambari.api.controller.spi.Schema;
+
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * HostComponent instance formatter.
+ */
+public class HostComponentInstanceFormatter extends BaseFormatter {
+ /**
+ * Related host.
+ */
+ public HrefEntry host;
+
+ /**
+ * Related component.
+ */
+ public HrefEntry component;
+
+ /**
+ * Constructor.
+ *
+ * @param resourceDefinition the resource definition
+ */
+ public HostComponentInstanceFormatter(ResourceDefinition resourceDefinition) {
+ super(resourceDefinition);
+ }
+
+ /**
+ * Extends the base format to add the host.
+ *
+ * @param result the result being formatted
+ * @param uriInfo url info
+ * @return the formatted hostComponent instance
+ */
+ @Override
+ public Object format(Result result, UriInfo uriInfo) {
+ Object o = super.format(result, uriInfo);
+ host = new HrefEntry(href.substring(0, href.indexOf("/host_components/")));
+
+ return o;
+ }
+
+ /**
+ * Add component.
+ *
+ * @param href the href to add
+ * @param r the resource being added
+ */
+ @Override
+ public void addSubResource(HrefEntry href, Resource r) {
+ component = href;
+ }
+
+ /**
+ * Build the component href.
+ *
+ * @param baseHref base url
+ * @param schema associated schema
+ * @param relation the component resource
+ * @return href for the associated component resource
+ */
+ @Override
+ String buildRelationHref(String baseHref, Schema schema, Resource relation) {
+ ResourceDefinition resourceDefinition = getResourceDefinition();
+ String clusterId = resourceDefinition.getResourceIds().get(Resource.Type.Cluster);
+ String serviceId = relation.getPropertyValue(schema.getKeyPropertyId(Resource.Type.Service));
+ String componentId = resourceDefinition.getId();
+ return href.substring(0, href.indexOf(clusterId) + clusterId.length() + 1) +
+ "services/" + serviceId + "/components/" + componentId;
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/HostInstanceFormatter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/HostInstanceFormatter.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/HostInstanceFormatter.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/HostInstanceFormatter.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,55 @@
+/**
+ * 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.services.formatters;
+
+import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.controller.spi.Resource;
+
+import java.util.*;
+
+/**
+ * Host instance formatter.
+ */
+public class HostInstanceFormatter extends BaseFormatter {
+ /**
+ * host_components collection.
+ */
+ public List<HrefEntry> host_components = new ArrayList<HrefEntry>();
+
+
+ /**
+ * Constructor.
+ *
+ * @param resourceDefinition the resource definition
+ */
+ public HostInstanceFormatter(ResourceDefinition resourceDefinition) {
+ super(resourceDefinition);
+ }
+
+ /**
+ * Add host_component href's.
+ *
+ * @param href the host_component href to add
+ * @param r the host_component resource being added
+ */
+ @Override
+ public void addSubResource(BaseFormatter.HrefEntry href, Resource r) {
+ host_components.add(href);
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ResultFormatter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ResultFormatter.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ResultFormatter.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ResultFormatter.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.services.formatters;
+
+
+import org.apache.ambari.api.services.Result;
+
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * Format internal result to format expected by client.
+ */
+public interface ResultFormatter {
+ /**
+ * Format the given result to a format expected by client.
+ *
+ * @param result internal result
+ * @param uriInfo URL info for request
+ * @return the formatted result
+ */
+ Object format(Result result, UriInfo uriInfo);
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ServiceInstanceFormatter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ServiceInstanceFormatter.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ServiceInstanceFormatter.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/services/formatters/ServiceInstanceFormatter.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,55 @@
+/**
+ * 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.services.formatters;
+
+import org.apache.ambari.api.resource.ResourceDefinition;
+import org.apache.ambari.api.controller.spi.Resource;
+
+import java.util.*;
+
+/**
+ * Service instance formatter.
+ */
+public class ServiceInstanceFormatter extends BaseFormatter {
+ /**
+ * components collection.
+ */
+ public List<HrefEntry> components = new ArrayList<HrefEntry>();
+
+ /**
+ * Constructor.
+ *
+ * @param resourceDefinition the resource definition
+ */
+ public ServiceInstanceFormatter(ResourceDefinition resourceDefinition) {
+ super(resourceDefinition);
+ }
+
+ /**
+ * Add component href's.
+ *
+ * @param href the component href to add
+ * @param r the component resource being added
+ */
+ @Override
+ public void addSubResource(BaseFormatter.HrefEntry href, Resource r) {
+ components.add(href);
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/key_properties.json
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/key_properties.json?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/key_properties.json (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/key_properties.json Sun Sep 23 18:01:49 2012
@@ -0,0 +1,67 @@
+{
+ "Cluster":{
+ "Cluster":{
+ "name":"cluster_name",
+ "category":"Clusters",
+ "temporal":false
+ }
+ },
+ "Service":{
+ "Cluster":{
+ "name":"cluster_name",
+ "category":"ServiceInfo",
+ "temporal":false
+ },
+ "Service":{
+ "name":"service_name",
+ "category":"Services",
+ "temporal":false
+ }
+ },
+ "Host":{
+ "Cluster":{
+ "name":"cluster_name",
+ "category":"Hosts",
+ "temporal":false
+ },
+ "Host":{
+ "name":"host_name",
+ "category":"Hosts",
+ "temporal":false
+ }
+ },
+ "Component":{
+ "Cluster":{
+ "name":"cluster_name",
+ "category":"ServiceComponentInfo",
+ "temporal":false
+ },
+ "Service":{
+ "name":"service_name",
+ "category":"ServiceComponents",
+ "temporal":false
+ },
+ "Component":{
+ "name":"component_name",
+ "category":"ServiceComponents",
+ "temporal":false
+ }
+ },
+ "HostComponent":{
+ "Cluster":{
+ "name":"cluster_name",
+ "category":"HostRoles",
+ "temporal":false
+ },
+ "Host":{
+ "name":"host_name",
+ "category":"HostRoles",
+ "temporal":false
+ },
+ "HostComponent":{
+ "name":"component_name",
+ "category":"HostRoles",
+ "temporal":false
+ }
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/properties.json
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/properties.json?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/properties.json (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/properties.json Sun Sep 23 18:01:49 2012
@@ -0,0 +1,418 @@
+{
+ "Cluster":{
+ "DB":[
+ {
+ "name":"cluster_name",
+ "category":"Clusters",
+ "temporal":false
+ },
+ {
+ "name":"version",
+ "category":"Clusters",
+ "temporal":false
+ },
+ {
+ "name":"state",
+ "category":"Clusters",
+ "temporal":false
+ }
+ ],
+ "JMX":[
+ ],
+ "GANGLIA":[
+ ]
+ },
+ "Service":{
+ "DB":[
+ {
+ "name":"service_name",
+ "category":"Services",
+ "temporal":false
+ },
+ {
+ "name":"description",
+ "category":"Services",
+ "temporal":false
+ },
+ {
+ "name":"display_name",
+ "category":"Services",
+ "temporal":false
+ },
+ {
+ "name":"attributes",
+ "category":"Services",
+ "temporal":false
+ },
+ {
+ "name":"cluster_name",
+ "category":"ServiceInfo",
+ "temporal":false
+ },
+ {
+ "name":"state",
+ "category":"ServiceInfo",
+ "temporal":false
+ }
+ ],
+ "JMX":[
+ ],
+ "GANGLIA":[
+ ]
+ },
+ "Host":{
+ "DB":[
+ {
+ "name":"cluster_name",
+ "category":"Hosts",
+ "temporal":false
+ },
+ {
+ "name":"host_name",
+ "category":"Hosts",
+ "temporal":false
+ },
+ {
+ "name":"ip",
+ "category":"Hosts",
+ "temporal":false
+ },
+ {
+ "name":"total_mem",
+ "category":"Hosts",
+ "temporal":false
+ },
+ {
+ "name":"cpu_count",
+ "category":"Hosts",
+ "temporal":false
+ },
+ {
+ "name":"os_arch",
+ "category":"Hosts",
+ "temporal":false
+ },
+ {
+ "name":"os_type",
+ "category":"Hosts",
+ "temporal":false
+ }
+ ],
+ "JMX":[
+ ],
+ "GANGLIA":[
+ ]
+ },
+ "Component":{
+ "DB":[
+ {
+ "name":"service_name",
+ "category":"ServiceComponents",
+ "temporal":false
+ },
+ {
+ "name":"component_name",
+ "category":"ServiceComponents",
+ "temporal":false
+ },
+ {
+ "name":"display_name",
+ "category":"ServiceComponents",
+ "temporal":false
+ },
+ {
+ "name":"description",
+ "category":"ServiceComponents",
+ "temporal":false
+ },
+ {
+ "name":"cluster_name",
+ "category":"ServiceComponentInfo",
+ "temporal":false
+ },
+ {
+ "name":"state",
+ "category":"ServiceComponentInfo",
+ "temporal":false
+ }
+ ],
+ "JMX":[
+ ],
+ "GANGLIA":[
+ ]
+ },
+ "HostComponent":{
+ "DB":[
+ {
+ "name":"role_id",
+ "category":"HostRoles",
+ "temporal":false
+ },
+ {
+ "name":"cluster_name",
+ "category":"HostRoles",
+ "temporal":false
+ },
+ {
+ "name":"host_name",
+ "category":"HostRoles",
+ "temporal":false
+ },
+ {
+ "name":"component_name",
+ "category":"HostRoles",
+ "temporal":false
+ },
+ {
+ "name":"state",
+ "category":"HostRoles",
+ "temporal":false
+ }
+ ],
+ "JMX":[
+ {
+ "name":"memNonHeapUsedM",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"memNonHeapCommittedM",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"memHeapUsedM",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"memHeapCommittedM",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"gcCount",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"gcTimeMillis",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"threadsNew",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"threadsRunnable",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"threadsBlocked",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"threadsWaiting",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"threadsTimedWaiting",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"threadsTerminated",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"logFatal",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"logError",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"logWarn",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"memHeapUsedM",
+ "category":"jvm",
+ "temporal":false
+ },
+ {
+ "name":"rpcAuthenticationSuccesses",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"rpcAuthenticationFailures",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"rpcAuthorizationSuccesses",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"rpcAuthorizationFailures",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"ReceivedBytes",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"SentBytes",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"RpcQueueTime_num_ops",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"RpcQueueTime_avg_time",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"RpcProcessingTime_num_ops",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"RpcProcessingTime_avg_time",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"NumOpenConnections",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"callQueueLen",
+ "category":"rpc",
+ "temporal":false
+ },
+ {
+ "name":"FilesCreated",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"FilesAppended",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"GetBlockLocations",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"FilesRenamed",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"GetListingOps",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"CreateFileOps",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"FilesDeleted",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"DeleteFileOps",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"FileInfoOps",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"AddBlockOps",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"Transactions_num_ops",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"Transactions_avg_time",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"Syncs_num_ops",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"Syncs_avg_time",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"JournalTransactionsBatchedInSync",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"blockReport_num_ops",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"blockReport_avg_time",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"SafemodeTime",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"fsImageLoadTime",
+ "category":"dfs",
+ "temporal":false
+ },
+ {
+ "name":"FilesInGetListingOps",
+ "category":"dfs",
+ "temporal":false
+ }
+
+ ],
+ "GANGLIA":[
+ ]
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/TestSuite.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;
+
+/**
+ * All unit tests.
+ */
+
+import org.apache.ambari.api.handlers.DelegatingRequestHandlerTest;
+import org.apache.ambari.api.handlers.ReadRequestHandlerTest;
+import org.apache.ambari.api.query.QueryImplTest;
+import org.apache.ambari.api.services.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ClusterServiceTest.class, HostServiceTest.class, ServiceServiceTest.class,
+ ComponentServiceTest.class, HostComponentServiceTest.class, DelegatingRequestHandlerTest.class,
+ ReadRequestHandlerTest.class, QueryImplTest.class})
+public class TestSuite {
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaHelperTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaHelperTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaHelperTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,52 @@
+/**
+ * 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.ganglia;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ *
+ */
+public class GangliaHelperTest {
+
+
+ @Ignore
+ @Test
+ public void testGetGangliaMetrics() throws Exception {
+ //MM/dd/yy HH:mm:ss
+
+ String target = "ec2-107-22-86-120.compute-1.amazonaws.com";
+ String cluster = "HDPNameNode";
+ String host = "domU-12-31-39-15-25-C7.compute-1.internal";
+ Date startTime = new SimpleDateFormat("MM/dd/yy HH:mm:ss").parse("09/12/12 10:00:00");
+ Date endTime = new SimpleDateFormat("MM/dd/yy HH:mm:ss").parse("09/12/12 16:15:00");
+ long step = 60;
+// String api = "rpcdetailed.rpcdetailed.sendHeartbeat_num_ops";
+ String metric = "cpu_nice";
+
+ List<GangliaMetric> metrics = GangliaHelper.getGangliaMetrics(target, cluster, host, metric, startTime, endTime, step);
+
+ System.out.println("GangliaHelperTest.testGetMetrics : api = " + metrics);
+
+ //TODO : assertions
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaPropertyProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaPropertyProviderTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaPropertyProviderTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/ganglia/GangliaPropertyProviderTest.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.ganglia;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class GangliaPropertyProviderTest {
+
+ @Ignore
+ @Test
+ public void testGet() throws Exception {
+// String target = "ec2-75-101-217-112.compute-1.amazonaws.com";
+//
+// GangliaPropertyProvider provider = new GangliaPropertyProvider(target);
+//
+// HostComponentId id = new HostComponentId("domU-12-31-39-0E-41-51.compute-1.internal", "HDPNameNode");
+//
+// List<String> selectList = new LinkedList<String>();
+// selectList.add("rpcdetailed.rpcdetailed.sendHeartbeat_num_ops");
+//
+// provider.get(id, selectList);
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ClusterControllerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ClusterControllerImplTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ClusterControllerImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ClusterControllerImplTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,171 @@
+/**
+ * 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.internal;
+
+import junit.framework.Assert;
+import org.apache.ambari.api.controller.spi.ClusterController;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.PropertyProvider;
+import org.apache.ambari.api.controller.spi.Request;
+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 org.apache.ambari.api.controller.utilities.PredicateBuilder;
+import org.apache.ambari.api.controller.utilities.PredicateHelper;
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public class ClusterControllerImplTest {
+
+ private static final Set<PropertyId> resourceProviderProperties = new HashSet<PropertyId>();
+
+ static {
+ resourceProviderProperties.add(Properties.getPropertyId("p1", "c1"));
+ resourceProviderProperties.add(Properties.getPropertyId("p2", "c1"));
+ resourceProviderProperties.add(Properties.getPropertyId("p3", "c1"));
+ resourceProviderProperties.add(Properties.getPropertyId("p4", "c2"));
+ }
+
+ private static final ResourceProvider resourceProvider = new ResourceProvider() {
+ @Override
+ public Set<Resource> getResources(Request request, Predicate predicate) {
+
+ Set<Resource> resources = new HashSet<Resource>();
+
+ for (int cnt = 0; cnt < 4; ++ cnt) {
+ ResourceImpl resource = new ResourceImpl(Resource.Type.Host);
+
+ resource.setProperty(Properties.getPropertyId("p1", "c1"), cnt);
+ resource.setProperty(Properties.getPropertyId("p2", "c1"), cnt % 2);
+ resource.setProperty(Properties.getPropertyId("p3", "c1"), "foo");
+ resource.setProperty(Properties.getPropertyId("p4", "c2"), "bar");
+ resources.add(resource);
+ }
+
+ return resources;
+ }
+
+ @Override
+ public Set<PropertyId> getPropertyIds() {
+ return resourceProviderProperties;
+ }
+ };
+
+ private static final Set<PropertyId> propertyProviderProperties = new HashSet<PropertyId>();
+
+ static {
+ propertyProviderProperties.add(Properties.getPropertyId("p5", "c3"));
+ propertyProviderProperties.add(Properties.getPropertyId("p6", "c3"));
+ propertyProviderProperties.add(Properties.getPropertyId("p7", "c4"));
+ propertyProviderProperties.add(Properties.getPropertyId("p8", "c4"));
+ }
+
+ private static final PropertyProvider propertyProvider = new PropertyProvider() {
+ @Override
+ public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) {
+
+ int cnt = 0;
+ for (Resource resource : resources){
+ resource.setProperty(Properties.getPropertyId("p5", "c3"), cnt + 100);
+ resource.setProperty(Properties.getPropertyId("p6", "c3"), cnt % 2);
+ resource.setProperty(Properties.getPropertyId("p7", "c4"), "monkey");
+ resource.setProperty(Properties.getPropertyId("p8", "c4"), "runner");
+ ++cnt;
+ }
+ return resources;
+ }
+
+ @Override
+ public Set<PropertyId> getPropertyIds() {
+ return propertyProviderProperties;
+ }
+ };
+
+ private static final List<PropertyProvider> propertyProviders = new LinkedList<PropertyProvider>();
+
+ static {
+ propertyProviders.add(propertyProvider);
+ }
+
+ private static final Map<String, PropertyId> keyPropertyIds = new HashMap<String, PropertyId>();
+
+ private static Map<Resource.Type, Schema> schemas = new HashMap<Resource.Type, Schema>();
+
+ static {
+ schemas.put(Resource.Type.Host, new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds));
+ }
+
+ private static final Set<PropertyId> propertyIds = new HashSet<PropertyId>();
+
+ static {
+ propertyIds.add(Properties.getPropertyId("p1", "c1"));
+ propertyIds.add(Properties.getPropertyId("p2", "c1"));
+ propertyIds.add(Properties.getPropertyId("p3", "c2"));
+ propertyIds.add(Properties.getPropertyId("p4", "c3"));
+ propertyIds.add(Properties.getPropertyId("p5", "c3"));
+ propertyIds.add(Properties.getPropertyId("p7", "c4"));
+ }
+
+ @Test
+ public void testGetResources() {
+ ClusterController controller = new ClusterControllerImpl(schemas);
+
+ Request request = new RequestImpl(propertyIds);
+
+ Iterable<Resource> iterable = controller.getResources(Resource.Type.Host, request, null);
+
+ int cnt = 0;
+ for (Resource resource : iterable) {
+ Assert.assertEquals(Resource.Type.Host, resource.getType());
+ ++cnt;
+ }
+ Assert.assertEquals(4, cnt);
+ }
+
+ @Test
+ public void testGetResourcesWithPredicate() {
+ ClusterController controller = new ClusterControllerImpl(schemas);
+
+ Request request = new RequestImpl(propertyIds);
+
+ Predicate predicate = new PredicateBuilder().property("p2", "c1").equals(1).toPredicate();
+
+ Iterable<Resource> iterable = controller.getResources(Resource.Type.Host, request, predicate);
+
+ int cnt = 0;
+ for (Resource resource : iterable) {
+ Assert.assertEquals(Resource.Type.Host, resource.getType());
+ ++cnt;
+ }
+ Assert.assertEquals(2, cnt);
+ }
+}
+
+
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/PropertyIdImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/PropertyIdImplTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/PropertyIdImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/PropertyIdImplTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,55 @@
+/**
+ * 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.internal;
+
+import junit.framework.Assert;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class PropertyIdImplTest {
+
+ @Test
+ public void testGetName() {
+ PropertyId propertyId = new PropertyIdImpl("p1", "c1", false);
+
+ Assert.assertEquals("p1", propertyId.getName());
+ }
+
+ @Test
+ public void testGetCategory() {
+ PropertyId propertyId = new PropertyIdImpl("p1", "c1", false);
+
+ Assert.assertEquals("c1", propertyId.getCategory());
+ }
+
+ @Test
+ public void testIsTemporal() {
+ PropertyId propertyId = new PropertyIdImpl("p1", "c1", false);
+
+ Assert.assertFalse(propertyId.isTemporal());
+
+ propertyId = new PropertyIdImpl("p1", "c1", true);
+
+ Assert.assertTrue(propertyId.isTemporal());
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/RequestImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/RequestImplTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/RequestImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/RequestImplTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,50 @@
+/**
+ * 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.internal;
+
+import junit.framework.Assert;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Request;
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ */
+public class RequestImplTest {
+
+ private static final Set<PropertyId> propertyIds = new HashSet<PropertyId>();
+
+ static {
+ propertyIds.add(Properties.getPropertyId("p1", "c1"));
+ propertyIds.add(Properties.getPropertyId("p2", "c1"));
+ propertyIds.add(Properties.getPropertyId("p3", "c2"));
+ propertyIds.add(Properties.getPropertyId("p4", "c3"));
+ }
+
+ @Test
+ public void testGetPropertyIds() {
+ Request request = new RequestImpl(propertyIds);
+
+ Assert.assertEquals(propertyIds, request.getPropertyIds());
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ResourceImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ResourceImplTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ResourceImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ResourceImplTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,70 @@
+/**
+ * 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.internal;
+
+import junit.framework.Assert;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class ResourceImplTest {
+
+ @Test
+ public void testGetType() {
+ Resource resource = new ResourceImpl(Resource.Type.Cluster);
+ Assert.assertEquals(Resource.Type.Cluster, resource.getType());
+
+ resource = new ResourceImpl(Resource.Type.Service);
+ Assert.assertEquals(Resource.Type.Service, resource.getType());
+
+ resource = new ResourceImpl(Resource.Type.Host);
+ Assert.assertEquals(Resource.Type.Host, resource.getType());
+
+ resource = new ResourceImpl(Resource.Type.Component);
+ Assert.assertEquals(Resource.Type.Component, resource.getType());
+
+ resource = new ResourceImpl(Resource.Type.HostComponent);
+ Assert.assertEquals(Resource.Type.HostComponent, resource.getType());
+ }
+
+ @Test
+ public void testSetGetProperty() {
+ Resource resource = new ResourceImpl(Resource.Type.Cluster);
+
+ PropertyId propertyId = Properties.getPropertyId("p1", "c1");
+ resource.setProperty(propertyId, "foo");
+ Assert.assertEquals("foo", resource.getPropertyValue(propertyId));
+
+ resource.setProperty(propertyId, 1);
+ Assert.assertEquals("1", resource.getPropertyValue(propertyId));
+
+ resource.setProperty(propertyId, (float) 1.99);
+ Assert.assertEquals("1.99", resource.getPropertyValue(propertyId));
+
+ resource.setProperty(propertyId, 1.99);
+ Assert.assertEquals("1.99", resource.getPropertyValue(propertyId));
+
+ resource.setProperty(propertyId, 65L);
+ Assert.assertEquals("65", resource.getPropertyValue(propertyId));
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/SchemaImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/SchemaImplTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/SchemaImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/SchemaImplTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,155 @@
+/**
+ * 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.internal;
+
+import junit.framework.Assert;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.PropertyProvider;
+import org.apache.ambari.api.controller.spi.Request;
+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 org.apache.ambari.api.controller.utilities.Properties;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *
+ */
+public class SchemaImplTest {
+
+ private static final Set<PropertyId> resourceProviderProperties = new HashSet<PropertyId>();
+
+ static {
+ resourceProviderProperties.add(Properties.getPropertyId("p1", "c1"));
+ resourceProviderProperties.add(Properties.getPropertyId("p2", "c1"));
+ resourceProviderProperties.add(Properties.getPropertyId("p3", "c1"));
+ resourceProviderProperties.add(Properties.getPropertyId("p4", "c2"));
+ }
+
+ private static final ResourceProvider resourceProvider = new ResourceProvider() {
+ @Override
+ public Set<Resource> getResources(Request request, Predicate predicate) {
+ return null;
+ }
+
+ @Override
+ public Set<PropertyId> getPropertyIds() {
+ return resourceProviderProperties;
+ }
+ };
+
+ private static final Set<PropertyId> propertyProviderProperties = new HashSet<PropertyId>();
+
+ static {
+ propertyProviderProperties.add(Properties.getPropertyId("p5", "c3"));
+ propertyProviderProperties.add(Properties.getPropertyId("p6", "c3"));
+ propertyProviderProperties.add(Properties.getPropertyId("p7", "c4"));
+ propertyProviderProperties.add(Properties.getPropertyId("p8", "c4"));
+ }
+
+ private static final PropertyProvider propertyProvider = new PropertyProvider() {
+ @Override
+ public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) {
+ return null;
+ }
+
+ @Override
+ public Set<PropertyId> getPropertyIds() {
+ return propertyProviderProperties;
+ }
+ };
+
+ private static final List<PropertyProvider> propertyProviders = new LinkedList<PropertyProvider>();
+
+ static {
+ propertyProviders.add(propertyProvider);
+ }
+
+ private static final Map<String, PropertyId> keyPropertyIds = new HashMap<String, PropertyId>();
+
+ static {
+ keyPropertyIds.put(Resource.Type.Cluster.toString(), Properties.getPropertyId("p1", "c1"));
+ keyPropertyIds.put(Resource.Type.Host.toString(), Properties.getPropertyId("p2", "c1"));
+ keyPropertyIds.put(Resource.Type.Component.toString(), Properties.getPropertyId("p3", "c1"));
+ }
+
+ @Test
+ public void testGetKeyPropertyId() {
+ Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+
+ Assert.assertEquals(Properties.getPropertyId("p1", "c1"), schema.getKeyPropertyId(Resource.Type.Cluster));
+ Assert.assertEquals(Properties.getPropertyId("p2", "c1"), schema.getKeyPropertyId(Resource.Type.Host));
+ Assert.assertEquals(Properties.getPropertyId("p3", "c1"), schema.getKeyPropertyId(Resource.Type.Component));
+ }
+
+ @Test
+ public void testGetCategories() {
+ Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+
+ Map<String, Set<String>> categories = schema.getCategories();
+ Assert.assertEquals(4, categories.size());
+ Assert.assertTrue(categories.containsKey("c1"));
+ Assert.assertTrue(categories.containsKey("c2"));
+ Assert.assertTrue(categories.containsKey("c3"));
+ Assert.assertTrue(categories.containsKey("c4"));
+
+ Set<String> properties = categories.get("c1");
+ Assert.assertEquals(3, properties.size());
+ Assert.assertTrue(properties.contains("p1"));
+ Assert.assertTrue(properties.contains("p2"));
+ Assert.assertTrue(properties.contains("p3"));
+
+ properties = categories.get("c2");
+ Assert.assertEquals(1, properties.size());
+ Assert.assertTrue(properties.contains("p4"));
+
+ properties = categories.get("c3");
+ Assert.assertEquals(2, properties.size());
+ Assert.assertTrue(properties.contains("p5"));
+ Assert.assertTrue(properties.contains("p6"));
+
+ properties = categories.get("c4");
+ Assert.assertEquals(2, properties.size());
+ Assert.assertTrue(properties.contains("p7"));
+ Assert.assertTrue(properties.contains("p8"));
+ }
+
+ @Test
+ public void testGetResourceProvider() {
+ Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+
+ Assert.assertSame(resourceProvider, schema.getResourceProvider());
+ }
+
+ @Test
+ public void testGetPropertyProviders() {
+ Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+
+ Assert.assertSame(propertyProviders, schema.getPropertyProviders());
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jmx/JMXHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jmx/JMXHelperTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jmx/JMXHelperTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jmx/JMXHelperTest.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.jmx;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class JMXHelperTest {
+
+ @Ignore
+ @Test
+ public void testGetJMXMetrics() throws Exception {
+
+ String target = "ec2-107-22-86-120.compute-1.amazonaws.com:50070";
+
+ JMXMetrics metrics = JMXHelper.getJMXMetrics(target, null);
+
+ System.out.println("GangliaHelperTest.testGetMetrics : api = " + metrics);
+
+ //TODO : assertions
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/AndPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/AndPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/AndPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/AndPredicateTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,76 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class AndPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId1 = new PropertyIdImpl("property1", "category1", false);
+ PropertyIdImpl propertyId2 = new PropertyIdImpl("property2", "category1", false);
+ PropertyIdImpl propertyId3 = new PropertyIdImpl("property3", "category1", false);
+
+ EqualsPredicate predicate1 = new EqualsPredicate(propertyId1, "v1");
+ EqualsPredicate predicate2 = new EqualsPredicate(propertyId2, "v2");
+ EqualsPredicate predicate3 = new EqualsPredicate(propertyId3, "v3");
+
+ AndPredicate andPredicate = new AndPredicate(predicate1, predicate2, predicate3);
+
+ resource.setProperty(propertyId1, "v1");
+ resource.setProperty(propertyId2, "monkey");
+ resource.setProperty(propertyId3, "v3");
+ Assert.assertFalse(andPredicate.evaluate(resource));
+
+ resource.setProperty(propertyId2, "v2");
+ Assert.assertTrue(andPredicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId1 = new PropertyIdImpl("property1", "category1", false);
+ PropertyIdImpl propertyId2 = new PropertyIdImpl("property2", "category1", false);
+ PropertyIdImpl propertyId3 = new PropertyIdImpl("property3", "category1", false);
+
+ EqualsPredicate predicate1 = new EqualsPredicate(propertyId1, "v1");
+ EqualsPredicate predicate2 = new EqualsPredicate(propertyId2, "v2");
+ EqualsPredicate predicate3 = new EqualsPredicate(propertyId3, "v3");
+
+ AndPredicate andPredicate = new AndPredicate(predicate1, predicate2, predicate3);
+
+ Set<PropertyId> ids = andPredicate.getPropertyIds();
+
+ Assert.assertEquals(3, ids.size());
+ Assert.assertTrue(ids.contains(propertyId1));
+ Assert.assertTrue(ids.contains(propertyId2));
+ Assert.assertTrue(ids.contains(propertyId3));
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/EqualsPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/EqualsPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/EqualsPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/EqualsPredicateTest.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.predicate;
+
+import junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class EqualsPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ Predicate predicate = new EqualsPredicate(propertyId, "bar");
+
+ resource.setProperty(propertyId, "monkey");
+ Assert.assertFalse(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "bar");
+ Assert.assertTrue(predicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ EqualsPredicate predicate = new EqualsPredicate(propertyId, "bar");
+
+ Set<PropertyId> ids = predicate.getPropertyIds();
+
+ Assert.assertEquals(1, ids.size());
+ Assert.assertTrue(ids.contains(propertyId));
+ }
+
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterEqualsPredicateTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,61 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class GreaterEqualsPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ Predicate predicate = new GreaterEqualsPredicate(propertyId, Comparables.forInteger(10));
+
+ resource.setProperty(propertyId, "1");
+ Assert.assertFalse(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "100");
+ Assert.assertTrue(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "10");
+ Assert.assertTrue(predicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ GreaterEqualsPredicate predicate = new GreaterEqualsPredicate(propertyId, Comparables.forInteger(10));
+
+ Set<PropertyId> ids = predicate.getPropertyIds();
+
+ Assert.assertEquals(1, ids.size());
+ Assert.assertTrue(ids.contains(propertyId));
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/GreaterPredicateTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,61 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class GreaterPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ Predicate predicate = new GreaterPredicate(propertyId, Comparables.forInteger(10));
+
+ resource.setProperty(propertyId, "1");
+ Assert.assertFalse(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "100");
+ Assert.assertTrue(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "10");
+ Assert.assertFalse(predicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ GreaterPredicate predicate = new GreaterPredicate(propertyId, Comparables.forInteger(10));
+
+ Set<PropertyId> ids = predicate.getPropertyIds();
+
+ Assert.assertEquals(1, ids.size());
+ Assert.assertTrue(ids.contains(propertyId));
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessEqualsPredicateTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,61 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class LessEqualsPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ Predicate predicate = new LessEqualsPredicate(propertyId, Comparables.forInteger(10));
+
+ resource.setProperty(propertyId, "1");
+ Assert.assertTrue(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "100");
+ Assert.assertFalse(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "10");
+ Assert.assertTrue(predicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ LessEqualsPredicate predicate = new LessEqualsPredicate(propertyId, Comparables.forInteger(10));
+
+ Set<PropertyId> ids = predicate.getPropertyIds();
+
+ Assert.assertEquals(1, ids.size());
+ Assert.assertTrue(ids.contains(propertyId));
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/LessPredicateTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,61 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class LessPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ Predicate predicate = new LessPredicate(propertyId, Comparables.forInteger(10));
+
+ resource.setProperty(propertyId, "1");
+ Assert.assertTrue(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "100");
+ Assert.assertFalse(predicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "10");
+ Assert.assertFalse(predicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ LessPredicate predicate = new LessPredicate(propertyId, Comparables.forInteger(10));
+
+ Set<PropertyId> ids = predicate.getPropertyIds();
+
+ Assert.assertEquals(1, ids.size());
+ Assert.assertTrue(ids.contains(propertyId));
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/NotPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/NotPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/NotPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/NotPredicateTest.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.predicate;
+
+import junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class NotPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ EqualsPredicate predicate = new EqualsPredicate(propertyId, "bar");
+ NotPredicate notPredicate = new NotPredicate(predicate);
+
+ resource.setProperty(propertyId, "monkey");
+ Assert.assertTrue(notPredicate.evaluate(resource));
+
+ resource.setProperty(propertyId, "bar");
+ Assert.assertFalse(notPredicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ EqualsPredicate predicate = new EqualsPredicate(propertyId, "bar");
+
+ Set<PropertyId> ids = predicate.getPropertyIds();
+
+ Assert.assertEquals(1, ids.size());
+ Assert.assertTrue(ids.contains(propertyId));
+ }
+
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/OrPredicateTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/OrPredicateTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/OrPredicateTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/OrPredicateTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,76 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Set;
+
+/**
+ *
+ */
+public class OrPredicateTest {
+
+ @Test
+ public void testApply() {
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+ PropertyIdImpl propertyId1 = new PropertyIdImpl("property1", "category1", false);
+ PropertyIdImpl propertyId2 = new PropertyIdImpl("property2", "category1", false);
+ PropertyIdImpl propertyId3 = new PropertyIdImpl("property3", "category1", false);
+
+ EqualsPredicate predicate1 = new EqualsPredicate(propertyId1, "v1");
+ EqualsPredicate predicate2 = new EqualsPredicate(propertyId2, "v2");
+ EqualsPredicate predicate3 = new EqualsPredicate(propertyId3, "v3");
+
+ OrPredicate orPredicate = new OrPredicate(predicate1, predicate2, predicate3);
+
+ resource.setProperty(propertyId1, "big");
+ resource.setProperty(propertyId2, "monkey");
+ resource.setProperty(propertyId3, "runner");
+ Assert.assertFalse(orPredicate.evaluate(resource));
+
+ resource.setProperty(propertyId2, "v2");
+ Assert.assertTrue(orPredicate.evaluate(resource));
+ }
+
+ @Test
+ public void testGetProperties() {
+ PropertyIdImpl propertyId1 = new PropertyIdImpl("property1", "category1", false);
+ PropertyIdImpl propertyId2 = new PropertyIdImpl("property2", "category1", false);
+ PropertyIdImpl propertyId3 = new PropertyIdImpl("property3", "category1", false);
+
+ EqualsPredicate predicate1 = new EqualsPredicate(propertyId1, "v1");
+ EqualsPredicate predicate2 = new EqualsPredicate(propertyId2, "v2");
+ EqualsPredicate predicate3 = new EqualsPredicate(propertyId3, "v3");
+
+ OrPredicate orPredicate = new OrPredicate(predicate1, predicate2, predicate3);
+
+ Set<PropertyId> ids = orPredicate.getPropertyIds();
+
+ Assert.assertEquals(3, ids.size());
+ Assert.assertTrue(ids.contains(propertyId1));
+ Assert.assertTrue(ids.contains(propertyId2));
+ Assert.assertTrue(ids.contains(propertyId3));
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/PredicateVisitorTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/PredicateVisitorTest.java?rev=1389109&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/PredicateVisitorTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/predicate/PredicateVisitorTest.java Sun Sep 23 18:01:49 2012
@@ -0,0 +1,83 @@
+/**
+ * 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 junit.framework.Assert;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class PredicateVisitorTest {
+
+ @Test
+ public void testVisitor() {
+
+ PropertyIdImpl propertyId = new PropertyIdImpl("foo", "category1", false);
+ EqualsPredicate equalsPredicate = new EqualsPredicate(propertyId, "bar");
+
+ TestPredicateVisitor visitor = new TestPredicateVisitor();
+ equalsPredicate.accept(visitor);
+
+ Assert.assertSame(equalsPredicate, visitor.visitedComparisonPredicate);
+ Assert.assertNull(visitor.visitedArrayPredicate);
+ Assert.assertNull(visitor.visitedUnaryPredicate);
+
+ AndPredicate andPredicate = new AndPredicate(equalsPredicate);
+
+ visitor = new TestPredicateVisitor();
+ andPredicate.accept(visitor);
+
+ Assert.assertNull(visitor.visitedComparisonPredicate);
+ Assert.assertSame(andPredicate, visitor.visitedArrayPredicate);
+ Assert.assertNull(visitor.visitedUnaryPredicate);
+
+ NotPredicate notPredicate = new NotPredicate(andPredicate);
+
+ visitor = new TestPredicateVisitor();
+ notPredicate.accept(visitor);
+
+ Assert.assertNull(visitor.visitedComparisonPredicate);
+ Assert.assertNull(visitor.visitedArrayPredicate);
+ Assert.assertSame(notPredicate, visitor.visitedUnaryPredicate);
+ }
+
+ public static class TestPredicateVisitor implements PredicateVisitor {
+
+ ComparisonPredicate visitedComparisonPredicate = null;
+ ArrayPredicate visitedArrayPredicate = null;
+ UnaryPredicate visitedUnaryPredicate = null;
+
+ @Override
+ public void acceptComparisonPredicate(ComparisonPredicate predicate) {
+ visitedComparisonPredicate = predicate;
+ }
+
+ @Override
+ public void acceptArrayPredicate(ArrayPredicate predicate) {
+ visitedArrayPredicate = predicate;
+ }
+
+ @Override
+ public void acceptUnaryPredicate(UnaryPredicate predicate) {
+ visitedUnaryPredicate = predicate;
+ }
+ }
+
+}