You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/10/01 20:22:53 UTC
svn commit: r1392497 - in /incubator/ambari/branches/AMBARI-666: ./
ambari-api/src/main/java/org/apache/ambari/api/controller/internal/
ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/
ambari-api/src/main/java/org/apache/ambari/api/contr...
Author: hitesh
Date: Mon Oct 1 18:22:52 2012
New Revision: 1392497
URL: http://svn.apache.org/viewvc?rev=1392497&view=rev
Log:
AMBARI-779. Introduce ManagementController interface. (Contributed by Tom Beerbower)
Added:
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/ResourceProviderImpl.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCHelper.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCManagementController.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ManagementController.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jdbc/
incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jdbc/JDBCManagementControllerTest.java (with props)
Removed:
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCResourceProvider.java
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/RequestImpl.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/SchemaImpl.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/SQLiteConnectionFactory.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Request.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ResourceProvider.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/ClusterControllerHelper.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/DBHelper.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/Properties.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/QueryImpl.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/key_properties.json
incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/properties.json
incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ClusterControllerImplTest.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/RequestImplTest.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/SchemaImplTest.java
incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/utilities/PropertiesTest.java
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Mon Oct 1 18:22:52 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
NEW FEATURES
+ AMBARI-779. Introduce ManagementController interface. (Tom Beerbower via hitesh)
+
AMBARI-755. Heartbeat handler: Update state as reported in heartbeat.
(jitendra)
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/RequestImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/RequestImpl.java?rev=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/RequestImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/RequestImpl.java Mon Oct 1 18:22:52 2012
@@ -22,6 +22,8 @@ import org.apache.ambari.api.controller.
import org.apache.ambari.api.controller.spi.Request;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -30,9 +32,11 @@ import java.util.Set;
public class RequestImpl implements Request {
private final Set<PropertyId> propertyIds;
+ private final Set<Map<PropertyId, String>> properties;
- public RequestImpl(Set<PropertyId> propertyIds) {
- this.propertyIds = Collections.unmodifiableSet(propertyIds);
+ public RequestImpl(Set<PropertyId> propertyIds, Set<Map<PropertyId, String>> properties) {
+ this.propertyIds = propertyIds == null ? Collections.unmodifiableSet(new HashSet<PropertyId>()) : Collections.unmodifiableSet(propertyIds);
+ this.properties = properties == null ? Collections.unmodifiableSet(new HashSet<Map<PropertyId, String>>()) : Collections.unmodifiableSet(properties);
}
@Override
@@ -41,6 +45,11 @@ public class RequestImpl implements Requ
}
@Override
+ public Set<Map<PropertyId, String>> getProperties() {
+ return properties;
+ }
+
+ @Override
public TemporalInfo getTemporalInfo(PropertyId id) {
return null; //TODO
}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/ResourceProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/ResourceProviderImpl.java?rev=1392497&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/ResourceProviderImpl.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/ResourceProviderImpl.java Mon Oct 1 18:22:52 2012
@@ -0,0 +1,218 @@
+/**
+ * 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 org.apache.ambari.api.controller.spi.ManagementController;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+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 java.util.HashSet;
+import java.util.Set;
+
+/**
+ */
+public abstract class ResourceProviderImpl implements ResourceProvider {
+
+ protected final Set<PropertyId> propertyIds;
+
+ private final ManagementController managementController;
+
+ private ResourceProviderImpl(Set<PropertyId> propertyIds, ManagementController managementController) {
+ this.propertyIds = propertyIds;
+ this.managementController = managementController;
+ }
+
+ @Override
+ public Set<PropertyId> getPropertyIds() {
+ return propertyIds;
+ }
+
+ public ManagementController getManagementController() {
+ return managementController;
+ }
+
+ public static ResourceProvider getResourceProvider(Resource.Type type, Set<PropertyId> propertyIds, ManagementController managementController) {
+
+ switch (type) {
+ case Cluster:
+ return new ClusterResourceProvider(propertyIds, managementController);
+ case Service:
+ return new ServiceResourceProvider(propertyIds, managementController);
+ case Component:
+ return new ComponentResourceProvider(propertyIds, managementController);
+ case Host:
+ return new HostResourceProvider(propertyIds, managementController);
+ case HostComponent:
+ return new HostComponentResourceProvider(propertyIds, managementController);
+ }
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+
+ protected Request getRequest(Request request) {
+ Set<PropertyId> propertyIds = new HashSet<PropertyId>(request.getPropertyIds());
+ if (propertyIds.size() == 0) {
+ request = new RequestImpl(this.propertyIds, null);
+ }
+ return request;
+ }
+
+ private static class ClusterResourceProvider extends ResourceProviderImpl{
+
+ private ClusterResourceProvider(Set<PropertyId> propertyIds, ManagementController managementController) {
+ super(propertyIds, managementController);
+ }
+
+ @Override
+ public void createResources(Request request) {
+ getManagementController().createClusters(request);
+ }
+
+ @Override
+ public Set<Resource> getResources(Request request, Predicate predicate) {
+ request = getRequest(request);
+ return getManagementController().getClusters(request, predicate);
+ }
+
+ @Override
+ public void updateResources(Request request, Predicate predicate) {
+ getManagementController().updateClusters(request, predicate);
+ }
+
+ @Override
+ public void deleteResources(Predicate predicate) {
+ getManagementController().deleteClusters(predicate);
+ }
+ }
+
+ private static class ServiceResourceProvider extends ResourceProviderImpl{
+
+ private ServiceResourceProvider(Set<PropertyId> propertyIds, ManagementController managementController) {
+ super(propertyIds, managementController);
+ }
+
+ @Override
+ public void createResources(Request request) {
+ getManagementController().createServices(request);
+ }
+
+ @Override
+ public Set<Resource> getResources(Request request, Predicate predicate) {
+ request = getRequest(request);
+ return getManagementController().getServices(request, predicate);
+ }
+
+ @Override
+ public void updateResources(Request request, Predicate predicate) {
+ getManagementController().updateServices(request, predicate);
+ }
+
+ @Override
+ public void deleteResources(Predicate predicate) {
+ getManagementController().deleteServices(predicate);
+ }
+ }
+
+ private static class ComponentResourceProvider extends ResourceProviderImpl{
+
+ private ComponentResourceProvider(Set<PropertyId> propertyIds, ManagementController managementController) {
+ super(propertyIds, managementController);
+ }
+
+ @Override
+ public void createResources(Request request) {
+ getManagementController().createComponents(request);
+ }
+
+ @Override
+ public Set<Resource> getResources(Request request, Predicate predicate) {
+ request = getRequest(request);
+ return getManagementController().getComponents(request, predicate);
+ }
+
+ @Override
+ public void updateResources(Request request, Predicate predicate) {
+ getManagementController().updateComponents(request, predicate);
+ }
+
+ @Override
+ public void deleteResources(Predicate predicate) {
+ getManagementController().deleteComponents(predicate);
+ }
+ }
+
+ private static class HostResourceProvider extends ResourceProviderImpl{
+
+ private HostResourceProvider(Set<PropertyId> propertyIds, ManagementController managementController) {
+ super(propertyIds, managementController);
+ }
+
+ @Override
+ public void createResources(Request request) {
+ getManagementController().createHosts(request);
+ }
+
+ @Override
+ public Set<Resource> getResources(Request request, Predicate predicate) {
+ request = getRequest(request);
+ return getManagementController().getHosts(request, predicate);
+ }
+
+ @Override
+ public void updateResources(Request request, Predicate predicate) {
+ getManagementController().updateHosts(request, predicate);
+ }
+
+ @Override
+ public void deleteResources(Predicate predicate) {
+ getManagementController().deleteHosts(predicate);
+ }
+ }
+
+ private static class HostComponentResourceProvider extends ResourceProviderImpl{
+
+ private HostComponentResourceProvider(Set<PropertyId> propertyIds, ManagementController managementController) {
+ super(propertyIds, managementController);
+ }
+
+ @Override
+ public void createResources(Request request) {
+ getManagementController().createHostComponents(request);
+ }
+
+ @Override
+ public Set<Resource> getResources(Request request, Predicate predicate) {
+ request = getRequest(request);
+ return getManagementController().getHostComponents(request, predicate);
+ }
+
+ @Override
+ public void updateResources(Request request, Predicate predicate) {
+ getManagementController().updateHostComponents(request, predicate);
+ }
+
+ @Override
+ public void deleteResources(Predicate predicate) {
+ getManagementController().deleteHostComponents(predicate);
+ }
+ }
+}
+
Propchange: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/ResourceProviderImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/SchemaImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/SchemaImpl.java?rev=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/SchemaImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/internal/SchemaImpl.java Mon Oct 1 18:22:52 2012
@@ -34,16 +34,13 @@ import java.util.Set;
* Default schema implementation.
*/
public class SchemaImpl implements Schema {
- private final Resource.Type type;
private final ResourceProvider resourceProvider;
private final List<PropertyProvider> propertyProviders;
- private final Map<String, PropertyId> keyPropertyIds;
+ private final Map<Resource.Type, PropertyId> keyPropertyIds;
- public SchemaImpl(Resource.Type type,
- ResourceProvider resourceProvider,
+ public SchemaImpl(ResourceProvider resourceProvider,
List<PropertyProvider> propertyProviders,
- Map<String, PropertyId> keyPropertyIds) {
- this.type = type;
+ Map<Resource.Type, PropertyId> keyPropertyIds) {
this.resourceProvider = resourceProvider;
this.propertyProviders = propertyProviders;
this.keyPropertyIds = keyPropertyIds;
@@ -51,7 +48,7 @@ public class SchemaImpl implements Schem
@Override
public PropertyId getKeyPropertyId(Resource.Type type) {
- return keyPropertyIds.get(type.toString());
+ return keyPropertyIds.get(type);
}
@Override
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCHelper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCHelper.java?rev=1392497&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCHelper.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCHelper.java Mon Oct 1 18:22:52 2012
@@ -0,0 +1,322 @@
+/**
+ * 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.jdbc;
+
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.internal.ResourceImpl;
+import org.apache.ambari.api.controller.predicate.BasePredicate;
+import org.apache.ambari.api.controller.predicate.PredicateVisitorAcceptor;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Request;
+import org.apache.ambari.api.controller.spi.Resource;
+import org.apache.ambari.api.controller.utilities.PredicateHelper;
+import org.apache.ambari.api.controller.utilities.Properties;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Helper class for JDBC related operations.
+ */
+public class JDBCHelper {
+
+ public static void createResources(ConnectionFactory connectionFactory, Request request) {
+ try {
+ Connection connection = connectionFactory.getConnection();
+
+ try {
+
+ Set<Map<PropertyId, String>> propertySet = request.getProperties();
+
+ for (Map<PropertyId, String> properties : propertySet) {
+ String sql = getInsertSQL(properties);
+
+ Statement statement = connection.createStatement();
+
+ statement.execute(sql);
+ }
+ } finally {
+ connection.close();
+ }
+
+ } catch (SQLException e) {
+ throw new IllegalStateException("DB error : ", e);
+ }
+ }
+
+ public static Set<Resource> getResources(ConnectionFactory connectionFactory, Resource.Type type, Request request, Predicate predicate) {
+
+ Set<Resource> resources = new HashSet<Resource>();
+ Set<PropertyId> propertyIds = new HashSet<PropertyId>(request.getPropertyIds());
+ if (predicate != null) {
+ propertyIds.addAll(PredicateHelper.getPropertyIds(predicate));
+ }
+
+ try {
+ Connection connection = connectionFactory.getConnection();
+
+ try {
+
+ Map<PropertyId, PropertyId> joinKeys = getJoins(connection, propertyIds);
+ String sql = getSelectSQL(propertyIds, predicate, joinKeys);
+ Statement statement = connection.createStatement();
+
+ ResultSet rs = statement.executeQuery(sql);
+
+ while (rs.next()) {
+ ResultSetMetaData metaData = rs.getMetaData();
+ int columnCount = metaData.getColumnCount();
+
+ final ResourceImpl resource = new ResourceImpl(type);
+ for (int i = 1; i <= columnCount; ++i) {
+ PropertyIdImpl propertyId = new PropertyIdImpl(metaData.getColumnName(i), metaData.getTableName(i), false);
+ if (propertyIds.contains(propertyId)) {
+ resource.setProperty(propertyId, rs.getString(i));
+ }
+ }
+ resources.add(resource);
+ }
+
+ } finally {
+ connection.close();
+ }
+
+ } catch (SQLException e) {
+ throw new IllegalStateException("DB error : ", e);
+ }
+
+ return resources;
+ }
+
+ public static void updateResources(ConnectionFactory connectionFactory, Request request, Predicate predicate) {
+
+ try {
+ Connection connection = connectionFactory.getConnection();
+ try {
+ Set<Map<PropertyId, String>> propertySet = request.getProperties();
+
+ Map<PropertyId, String> properties = propertySet.iterator().next();
+
+ String sql = getUpdateSQL(properties, predicate);
+
+ Statement statement = connection.createStatement();
+
+ statement.execute(sql);
+ } finally {
+ connection.close();
+ }
+
+ } catch (SQLException e) {
+ throw new IllegalStateException("DB error : ", e);
+ }
+ }
+
+ public static void deleteResources(ConnectionFactory connectionFactory, Predicate predicate) {
+ try {
+ Connection connection = connectionFactory.getConnection();
+ try {
+ String sql = getDeleteSQL(predicate);
+
+ Statement statement = connection.createStatement();
+ statement.execute(sql);
+ } finally {
+ connection.close();
+ }
+
+ } catch (SQLException e) {
+ throw new IllegalStateException("DB error : ", e);
+ }
+ }
+
+
+ // ----- Helper methods ----------------------------------------------------
+
+ private static String getInsertSQL(Map<PropertyId, String> properties) {
+
+ StringBuilder columns = new StringBuilder();
+ StringBuilder values = new StringBuilder();
+ String table = null;
+
+
+ for (Map.Entry<PropertyId, String> entry : properties.entrySet()) {
+ PropertyId propertyId = entry.getKey();
+ String propertyValue = entry.getValue();
+
+ table = propertyId.getCategory();
+
+
+ if (columns.length() > 0) {
+ columns.append(", ");
+ }
+ columns.append(propertyId.getName());
+
+ if (values.length() > 0) {
+ values.append(", ");
+ }
+ values.append("'");
+ values.append(propertyValue);
+ values.append("'");
+ }
+
+ return "insert into " + table + " (" +
+ columns + ") values (" +values + ")";
+ }
+
+ private static String getSelectSQL(Set<PropertyId> propertyIds, Predicate predicate, Map<PropertyId, PropertyId> joinKeys) {
+
+ StringBuilder columns = new StringBuilder();
+ Set<String> tableSet = new HashSet<String>();
+
+ for (PropertyId propertyId : propertyIds) {
+ if (columns.length() > 0) {
+ columns.append(", ");
+ }
+ columns.append(propertyId.getCategory()).append(".").append(propertyId.getName());
+ tableSet.add(propertyId.getCategory());
+ }
+
+ boolean haveWhereClause = false;
+ StringBuilder whereClause = new StringBuilder();
+ if (predicate != null &&
+ propertyIds.containsAll(PredicateHelper.getPropertyIds(predicate)) &&
+ predicate instanceof PredicateVisitorAcceptor) {
+
+ SQLPredicateVisitor visitor = new SQLPredicateVisitor();
+ ((PredicateVisitorAcceptor) predicate).accept(visitor);
+ whereClause.append(visitor.getSQL());
+ haveWhereClause = true;
+ }
+
+ StringBuilder joinClause = new StringBuilder();
+
+ if (tableSet.size() > 1) {
+ for (Map.Entry<PropertyId, PropertyId> entry : joinKeys.entrySet()) {
+ String category1 = entry.getKey().getCategory();
+ String category2 = entry.getValue().getCategory();
+ if (tableSet.contains(category1) && tableSet.contains(category2)){
+ if (haveWhereClause || joinClause.length() > 0) {
+ joinClause.append(" and ");
+ }
+ joinClause.append(category1).append(".").append(entry.getKey().getName());
+ joinClause.append("=");
+ joinClause.append(category2).append(".").append(entry.getValue().getName());
+ tableSet.add(category1);
+ tableSet.add(category2);
+ }
+ }
+ haveWhereClause = true;
+ }
+
+ StringBuilder tables = new StringBuilder();
+
+ for (String table : tableSet) {
+ if (tables.length() > 0) {
+ tables.append(", ");
+ }
+ tables.append(table);
+ }
+
+ String sql = "select " + columns + " from " + tables;
+
+ if (haveWhereClause) {
+ sql = sql + " where " + whereClause + joinClause;
+ }
+ return sql;
+ }
+
+ private static String getDeleteSQL(Predicate predicate) {
+
+ StringBuilder whereClause = new StringBuilder();
+ if (predicate instanceof BasePredicate) {
+
+ BasePredicate basePredicate = (BasePredicate) predicate;
+
+ SQLPredicateVisitor visitor = new SQLPredicateVisitor();
+ basePredicate.accept(visitor);
+ whereClause.append(visitor.getSQL());
+
+ String table = basePredicate.getPropertyIds().iterator().next().getCategory();
+
+ return "delete from " + table + " where " + whereClause;
+ }
+ throw new IllegalStateException("Can't generate SQL.");
+ }
+
+ private static String getUpdateSQL(Map<PropertyId, String> properties, Predicate predicate) {
+
+ if (predicate instanceof BasePredicate) {
+
+ StringBuilder whereClause = new StringBuilder();
+
+ BasePredicate basePredicate = (BasePredicate) predicate;
+
+ SQLPredicateVisitor visitor = new SQLPredicateVisitor();
+ basePredicate.accept(visitor);
+ whereClause.append(visitor.getSQL());
+
+ String table = basePredicate.getPropertyIds().iterator().next().getCategory();
+
+
+ StringBuilder setClause = new StringBuilder();
+ for (Map.Entry<PropertyId, String> entry : properties.entrySet()) {
+
+ if (setClause.length() > 0) {
+ setClause.append(", ");
+ }
+ setClause.append(entry.getKey().getName());
+ setClause.append(" = ");
+ setClause.append("'");
+ setClause.append(entry.getValue());
+ setClause.append("'");
+ }
+
+ return "update " + table + " set " + setClause + " where " + whereClause;
+ }
+ throw new IllegalStateException("Can't generate SQL.");
+ }
+
+ private static Map<PropertyId, PropertyId> getJoins(Connection connection, Set<PropertyId> tables) throws SQLException {
+ Map<PropertyId, PropertyId> joins = new HashMap<PropertyId, PropertyId>();
+ DatabaseMetaData meta = connection.getMetaData();
+
+ for (PropertyId propertyId : tables) {
+ ResultSet rs = meta.getImportedKeys(connection.getCatalog(), null, propertyId.getCategory());
+
+ while (rs.next()) {
+
+ PropertyId pkPropertyId = Properties.getPropertyId(
+ rs.getString("PKCOLUMN_NAME"), rs.getString("PKTABLE_NAME"));
+
+ PropertyId fkPropertyId = Properties.getPropertyId(
+ rs.getString("FKCOLUMN_NAME"), rs.getString("FKTABLE_NAME"));
+ joins.put(pkPropertyId, fkPropertyId);
+ }
+ }
+ return joins;
+ }
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCManagementController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCManagementController.java?rev=1392497&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCManagementController.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCManagementController.java Mon Oct 1 18:22:52 2012
@@ -0,0 +1,138 @@
+/**
+ * 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.jdbc;
+
+import org.apache.ambari.api.controller.spi.ManagementController;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.Request;
+import org.apache.ambari.api.controller.spi.Resource;
+
+import java.util.Set;
+
+/**
+ * Generic JDBC implementation of a management controller.
+ */
+public class JDBCManagementController implements ManagementController {
+
+ private final ConnectionFactory connectionFactory;
+
+ public JDBCManagementController(ConnectionFactory connectionFactory) {
+ this.connectionFactory = connectionFactory;
+ }
+
+ @Override
+ public void createClusters(Request request) {
+ JDBCHelper.createResources(connectionFactory, request);
+ }
+
+ @Override
+ public void createServices(Request request) {
+ JDBCHelper.createResources(connectionFactory, request);
+ }
+
+ @Override
+ public void createComponents(Request request) {
+ JDBCHelper.createResources(connectionFactory, request);
+ }
+
+ @Override
+ public void createHosts(Request request) {
+ JDBCHelper.createResources(connectionFactory, request);
+ }
+
+ @Override
+ public void createHostComponents(Request request) {
+ JDBCHelper.createResources(connectionFactory, request);
+ }
+
+ @Override
+ public Set<Resource> getClusters(Request request, Predicate predicate) {
+ return JDBCHelper.getResources(connectionFactory, Resource.Type.Cluster, request, predicate);
+ }
+
+ @Override
+ public Set<Resource> getServices(Request request, Predicate predicate) {
+ return JDBCHelper.getResources(connectionFactory, Resource.Type.Service, request, predicate);
+ }
+
+ @Override
+ public Set<Resource> getComponents(Request request, Predicate predicate) {
+ return JDBCHelper.getResources(connectionFactory, Resource.Type.Component, request, predicate);
+ }
+
+ @Override
+ public Set<Resource> getHosts(Request request, Predicate predicate) {
+ return JDBCHelper.getResources(connectionFactory, Resource.Type.Host, request, predicate);
+ }
+
+ @Override
+ public Set<Resource> getHostComponents(Request request, Predicate predicate) {
+ return JDBCHelper.getResources(connectionFactory, Resource.Type.HostComponent, request, predicate);
+ }
+
+ @Override
+ public void updateClusters(Request request, Predicate predicate) {
+ JDBCHelper.updateResources(connectionFactory, request, predicate);
+ }
+
+ @Override
+ public void updateServices(Request request, Predicate predicate) {
+ JDBCHelper.updateResources(connectionFactory, request, predicate);
+ }
+
+ @Override
+ public void updateComponents(Request request, Predicate predicate) {
+ JDBCHelper.updateResources(connectionFactory, request, predicate);
+ }
+
+ @Override
+ public void updateHosts(Request request, Predicate predicate) {
+ JDBCHelper.updateResources(connectionFactory, request, predicate);
+ }
+
+ @Override
+ public void updateHostComponents(Request request, Predicate predicate) {
+ JDBCHelper.updateResources(connectionFactory, request, predicate);
+ }
+
+ @Override
+ public void deleteClusters(Predicate predicate) {
+ JDBCHelper.deleteResources(connectionFactory, predicate);
+ }
+
+ @Override
+ public void deleteServices(Predicate predicate) {
+ JDBCHelper.deleteResources(connectionFactory, predicate);
+ }
+
+ @Override
+ public void deleteComponents(Predicate predicate) {
+ JDBCHelper.deleteResources(connectionFactory, predicate);
+ }
+
+ @Override
+ public void deleteHosts(Predicate predicate) {
+ JDBCHelper.deleteResources(connectionFactory, predicate);
+ }
+
+ @Override
+ public void deleteHostComponents(Predicate predicate) {
+ JDBCHelper.deleteResources(connectionFactory, predicate);
+ }
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/JDBCManagementController.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/SQLiteConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/SQLiteConnectionFactory.java?rev=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/SQLiteConnectionFactory.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/jdbc/SQLiteConnectionFactory.java Mon Oct 1 18:22:52 2012
@@ -27,11 +27,12 @@ import java.sql.SQLException;
*/
public class SQLiteConnectionFactory implements ConnectionFactory {
- private static String DB_FILE_NAME = System.getProperty("ambariapi.dbfile", "src/test/resources/data.db");
+ public static final String CONNECTION_URL = "jdbc:sqlite:";
- public static final String CONNECTION_URL = "jdbc:sqlite:" + DB_FILE_NAME;
+ private final String dbFile;
- public SQLiteConnectionFactory() {
+ public SQLiteConnectionFactory(String dbFile) {
+ this.dbFile = dbFile;
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
@@ -41,6 +42,6 @@ public class SQLiteConnectionFactory imp
@Override
public Connection getConnection() throws SQLException {
- return DriverManager.getConnection(CONNECTION_URL);
+ return DriverManager.getConnection(CONNECTION_URL + dbFile);
}
}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ManagementController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ManagementController.java?rev=1392497&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ManagementController.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ManagementController.java Mon Oct 1 18:22:52 2012
@@ -0,0 +1,229 @@
+/**
+ * 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;
+
+/**
+ * Management controller interface.
+ */
+public interface ManagementController {
+
+
+ // ----- Create -----------------------------------------------------------
+
+ /**
+ * Create the clusters defined by the properties in the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the clusters to be created
+ */
+ public void createClusters(Request request);
+
+ /**
+ * Create the services defined by the properties in the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the services to be created
+ */
+ public void createServices(Request request);
+
+ /**
+ * Create the components defined by the properties in the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the components to be created
+ */
+ public void createComponents(Request request);
+
+ /**
+ * Create the hosts defined by the properties in the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the hosts to be created
+ */
+ public void createHosts(Request request);
+
+ /**
+ * Create the host components defined by the properties in the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the host components to be created
+ */
+ public void createHostComponents(Request request);
+
+
+ // ----- Read -------------------------------------------------------------
+
+ /**
+ * Get a set of cluster {@link Resource resources} based on the given request and predicate
+ * information.
+ *
+ * @param request the request object which defines the desired set of properties
+ * @param predicate the predicate object which can be used to filter which
+ * clusters are returned
+ * @return a set of cluster resources based on the given request and predicate information
+ */
+ public Set<Resource> getClusters(Request request, Predicate predicate);
+
+ /**
+ * Get a set of service {@link Resource resources} based on the given request and predicate
+ * information.
+ *
+ * @param request the request object which defines the desired set of properties
+ * @param predicate the predicate object which can be used to filter which
+ * services are returned
+ * @return a set of service resources based on the given request and predicate information
+ */
+ public Set<Resource> getServices(Request request, Predicate predicate);
+
+ /**
+ * Get a set of component {@link Resource resources} based on the given request and predicate
+ * information.
+ *
+ * @param request the request object which defines the desired set of properties
+ * @param predicate the predicate object which can be used to filter which
+ * components are returned
+ * @return a set of component resources based on the given request and predicate information
+ */
+ public Set<Resource> getComponents(Request request, Predicate predicate);
+
+ /**
+ * Get a set of host {@link Resource resources} based on the given request and predicate
+ * information.
+ *
+ * @param request the request object which defines the desired set of properties
+ * @param predicate the predicate object which can be used to filter which
+ * hosts are returned
+ * @return a set of host resources based on the given request and predicate information
+ */
+ public Set<Resource> getHosts(Request request, Predicate predicate);
+
+ /**
+ * Get a set of host component {@link Resource resources} based on the given request and predicate
+ * information.
+ *
+ * @param request the request object which defines the desired set of properties
+ * @param predicate the predicate object which can be used to filter which
+ * host components are returned
+ * @return a set of host component resources based on the given request and predicate information
+ */
+ public Set<Resource> getHostComponents(Request request, Predicate predicate);
+
+
+ // ----- Update -----------------------------------------------------------
+
+ /**
+ * Update the clusters selected by the given predicate with the properties
+ * from the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the clusters to be updated
+ * @param predicate the predicate object which can be used to filter which
+ * clusters are updated
+ */
+ public void updateClusters(Request request, Predicate predicate);
+
+ /**
+ * Update the services selected by the given predicate with the properties
+ * from the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the services to be updated
+ * @param predicate the predicate object which can be used to filter which
+ * services are updated
+ */
+ public void updateServices(Request request, Predicate predicate);
+
+ /**
+ * Update the components selected by the given predicate with the properties
+ * from the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the components to be updated
+ * @param predicate the predicate object which can be used to filter which
+ * components are updated
+ */
+ public void updateComponents(Request request, Predicate predicate);
+
+ /**
+ * Update the hosts selected by the given predicate with the properties
+ * from the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the hosts to be updated
+ * @param predicate the predicate object which can be used to filter which
+ * hosts are updated
+ */
+ public void updateHosts(Request request, Predicate predicate);
+
+ /**
+ * Update the host components selected by the given predicate with the properties
+ * from the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the host components to be updated
+ * @param predicate the predicate object which can be used to filter which
+ * host components are updated
+ */
+ public void updateHostComponents(Request request, Predicate predicate);
+
+
+ // ----- Delete -----------------------------------------------------------
+
+ /**
+ * Delete the clusters selected by the given predicate.
+ *
+ * @param predicate the predicate object which can be used to filter which
+ * clusters are deleted
+ */
+ public void deleteClusters(Predicate predicate);
+
+ /**
+ * Delete the services selected by the given predicate.
+ *
+ * @param predicate the predicate object which can be used to filter which
+ * services are deleted
+ */
+ public void deleteServices(Predicate predicate);
+
+ /**
+ * Delete the components selected by the given predicate.
+ *
+ * @param predicate the predicate object which can be used to filter which
+ * components are deleted
+ */
+ public void deleteComponents(Predicate predicate);
+
+ /**
+ * Delete the hosts selected by the given predicate.
+ *
+ * @param predicate the predicate object which can be used to filter which
+ * hosts are deleted
+ */
+ public void deleteHosts(Predicate predicate);
+
+ /**
+ * Delete the host components selected by the given predicate.
+ *
+ * @param predicate the predicate object which can be used to filter which
+ * host components are deleted
+ */
+ public void deleteHostComponents(Predicate predicate);
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ManagementController.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Request.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/Request.java Mon Oct 1 18:22:52 2012
@@ -17,6 +17,7 @@
*/
package org.apache.ambari.api.controller.spi;
+import java.util.Map;
import java.util.Set;
/**
@@ -34,6 +35,7 @@ public interface Request {
*/
public Set<PropertyId> getPropertyIds();
+ public Set<Map<PropertyId, String>> getProperties();
/**
* Get the {@link TemporalInfo temporal information} for the given property
* id for this request, if any.
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ResourceProvider.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/spi/ResourceProvider.java Mon Oct 1 18:22:52 2012
@@ -28,6 +28,15 @@ import java.util.Set;
* for a given request.
*/
public interface ResourceProvider {
+
+ /**
+ * Create the resources defined by the properties in the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the resources to be created
+ */
+ public void createResources(Request request);
+
/**
* Get a set of {@link Resource resources} based on the given request and predicate
* information.
@@ -44,14 +53,33 @@ public interface ResourceProvider {
* 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
+ * @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);
/**
+ * Update the resources selected by the given predicate with the properties
+ * from the given request object.
+ *
+ * @param request the request object which defines the set of properties
+ * for the resources to be updated
+ * @param predicate the predicate object which can be used to filter which
+ * resources are updated
+ */
+ public void updateResources(Request request, Predicate predicate);
+
+ /**
+ * Delete the resources selected by the given predicate.
+ *
+ * @param predicate the predicate object which can be used to filter which
+ * resources are deleted
+ */
+ public void deleteResources(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
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/ClusterControllerHelper.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/ClusterControllerHelper.java Mon Oct 1 18:22:52 2012
@@ -19,11 +19,13 @@
package org.apache.ambari.api.controller.utilities;
import org.apache.ambari.api.controller.internal.ClusterControllerImpl;
+import org.apache.ambari.api.controller.internal.PropertyIdImpl;
+import org.apache.ambari.api.controller.internal.ResourceProviderImpl;
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.jdbc.JDBCManagementController;
import org.apache.ambari.api.controller.spi.ClusterController;
+import org.apache.ambari.api.controller.spi.ManagementController;
+import org.apache.ambari.api.controller.spi.PropertyId;
import org.apache.ambari.api.controller.spi.PropertyProvider;
import org.apache.ambari.api.controller.spi.Resource;
import org.apache.ambari.api.controller.spi.ResourceProvider;
@@ -40,11 +42,7 @@ import java.util.Map;
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());
}
@@ -55,15 +53,22 @@ public class ClusterControllerHelper {
Map<Resource.Type, Schema> schemas = new HashMap<Resource.Type, Schema>();
schemas.put(Resource.Type.Cluster, getResourceSchema(Resource.Type.Cluster));
+ schemas.put(Resource.Type.Service, getResourceSchema(Resource.Type.Service));
+ schemas.put(Resource.Type.Host, getResourceSchema(Resource.Type.Host));
+ schemas.put(Resource.Type.Component, getResourceSchema(Resource.Type.Component));
+ schemas.put(Resource.Type.HostComponent, getResourceSchema(Resource.Type.HostComponent));
return schemas;
}
private static Schema getResourceSchema(Resource.Type type) {
- ResourceProvider resourceProvider = JDBCResourceProvider.create(CONNECTION_FACTORY, type);
+ ManagementController managementController = new JDBCManagementController(DBHelper.CONNECTION_FACTORY);
+
+ ResourceProvider resourceProvider = ResourceProviderImpl.getResourceProvider(type, Properties.getPropertyIds(type, "DB"), managementController);
+
List<PropertyProvider> propertyProviders = new LinkedList<PropertyProvider>();
- return new SchemaImpl(type, resourceProvider, propertyProviders, Properties.getKeyPropertyIds(type));
+ return new SchemaImpl(resourceProvider, propertyProviders, Properties.getKeyPropertyIds(type));
}
}
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/DBHelper.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/DBHelper.java Mon Oct 1 18:22:52 2012
@@ -34,8 +34,9 @@ import java.util.Map;
*
*/
public class DBHelper {
+ private static String DB_FILE_NAME = System.getProperty("ambariapi.dbfile", "src/test/resources/data.db");
- public static final ConnectionFactory CONNECTION_FACTORY = new SQLiteConnectionFactory();
+ public static final ConnectionFactory CONNECTION_FACTORY = new SQLiteConnectionFactory(DB_FILE_NAME);
private static final Map<String, String> HOSTS = readHosts();
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/Properties.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/controller/utilities/Properties.java Mon Oct 1 18:22:52 2012
@@ -36,8 +36,8 @@ 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);
+ private static final Map<Resource.Type, Map<String, Set<PropertyId>>> PROPERTY_IDS = readPropertyIds(PROPERTIES_FILE);
+ private static final Map<Resource.Type, Map<Resource.Type, PropertyId>> KEY_PROPERTY_IDS = readKeyPropertyIds(KEY_PROPERTIES_FILE);
public static PropertyId getPropertyId(String name, String category) {
return new PropertyIdImpl(name, category, false);
@@ -49,37 +49,36 @@ public class Properties {
public static Set<PropertyId> getPropertyIds(Resource.Type resourceType, String providerKey) {
- Map<String, Set<PropertyId>> propertyIds = PROPERTY_IDS.get(resourceType.toString());
+ Map<String, Set<PropertyId>> propertyIds = PROPERTY_IDS.get(resourceType);
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());
+ public static Map<Resource.Type, PropertyId> getKeyPropertyIds(Resource.Type resourceType) {
+ return KEY_PROPERTY_IDS.get(resourceType);
}
- private static Map<String, Map<String, Set<PropertyId>>> readPropertyIds(String filename) {
+ private static Map<Resource.Type, 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>>>>() {
+ return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<Resource.Type, 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) {
+ private static Map<Resource.Type, Map<Resource.Type, PropertyId>> readKeyPropertyIds(String filename) {
ObjectMapper mapper = new ObjectMapper();
try {
- return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<String, Map<String, PropertyIdImpl>>>() {
+ return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<Resource.Type, Map<Resource.Type, PropertyIdImpl>>>() {
});
} catch (IOException e) {
throw new IllegalStateException("Can't read properties file " + filename, e);
}
}
-
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/QueryImpl.java?rev=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/QueryImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/java/org/apache/ambari/api/query/QueryImpl.java Mon Oct 1 18:22:52 2012
@@ -159,7 +159,7 @@ public class QueryImpl implements Query
setProperties.add(new PropertyIdImpl(property, group, false));
}
}
- return new RequestImpl(setProperties);
+ return new RequestImpl(setProperties, null);
}
//todo
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/key_properties.json (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/key_properties.json Mon Oct 1 18:22:52 2012
@@ -14,7 +14,7 @@
},
"Service":{
"name":"service_name",
- "category":"Services",
+ "category":"ServiceInfo",
"temporal":false
}
},
@@ -38,12 +38,12 @@
},
"Service":{
"name":"service_name",
- "category":"ServiceComponents",
+ "category":"ServiceComponentInfo",
"temporal":false
},
"Component":{
"name":"component_name",
- "category":"ServiceComponents",
+ "category":"ServiceComponentInfo",
"temporal":false
}
},
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/properties.json (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/main/resources/properties.json Mon Oct 1 18:22:52 2012
@@ -26,32 +26,32 @@
"DB":[
{
"name":"service_name",
- "category":"Services",
+ "category":"ServiceInfo",
"temporal":false
},
{
- "name":"description",
- "category":"Services",
+ "name":"cluster_name",
+ "category":"ServiceInfo",
"temporal":false
},
{
- "name":"display_name",
- "category":"Services",
+ "name":"state",
+ "category":"ServiceInfo",
"temporal":false
},
{
- "name":"attributes",
+ "name":"description",
"category":"Services",
"temporal":false
},
{
- "name":"cluster_name",
- "category":"ServiceInfo",
+ "name":"display_name",
+ "category":"Services",
"temporal":false
},
{
- "name":"state",
- "category":"ServiceInfo",
+ "name":"attributes",
+ "category":"Services",
"temporal":false
}
],
@@ -107,32 +107,32 @@
"DB":[
{
"name":"service_name",
- "category":"ServiceComponents",
+ "category":"ServiceComponentInfo",
"temporal":false
},
{
"name":"component_name",
- "category":"ServiceComponents",
+ "category":"ServiceComponentInfo",
"temporal":false
},
{
- "name":"display_name",
- "category":"ServiceComponents",
+ "name":"cluster_name",
+ "category":"ServiceComponentInfo",
"temporal":false
},
{
- "name":"description",
- "category":"ServiceComponents",
+ "name":"state",
+ "category":"ServiceComponentInfo",
"temporal":false
},
{
- "name":"cluster_name",
- "category":"ServiceComponentInfo",
+ "name":"display_name",
+ "category":"ServiceComponents",
"temporal":false
},
{
- "name":"state",
- "category":"ServiceComponentInfo",
+ "name":"description",
+ "category":"ServiceComponents",
"temporal":false
}
],
@@ -169,7 +169,7 @@
"temporal":false
}
],
- "JMX":[
+ "JMX":[
{
"name":"memNonHeapUsedM",
"category":"jvm",
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ClusterControllerImplTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/ClusterControllerImplTest.java Mon Oct 1 18:22:52 2012
@@ -28,10 +28,10 @@ import org.apache.ambari.api.controller.
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.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -73,6 +73,21 @@ public class ClusterControllerImplTest {
}
@Override
+ public void createResources(Request request) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void updateResources(Request request, Predicate predicate) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void deleteResources(Predicate predicate) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
public Set<PropertyId> getPropertyIds() {
return resourceProviderProperties;
}
@@ -114,12 +129,22 @@ public class ClusterControllerImplTest {
propertyProviders.add(propertyProvider);
}
- private static final Map<String, PropertyId> keyPropertyIds = new HashMap<String, PropertyId>();
+ private static final Map<Resource.Type, PropertyId> keyPropertyIds = new HashMap<Resource.Type, PropertyId>();
private static Map<Resource.Type, Schema> schemas = new HashMap<Resource.Type, Schema>();
+ private static final SchemaImpl hostSchema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
+ private static final SchemaImpl serviceSchema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
+ private static final SchemaImpl clusterSchema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
+ private static final SchemaImpl componentSchema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
+ private static final SchemaImpl hostComponentSchema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
+
static {
- schemas.put(Resource.Type.Host, new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds));
+ schemas.put(Resource.Type.Host, hostSchema);
+ schemas.put(Resource.Type.Service, serviceSchema);
+ schemas.put(Resource.Type.Cluster, clusterSchema);
+ schemas.put(Resource.Type.Component, componentSchema);
+ schemas.put(Resource.Type.HostComponent, hostComponentSchema);
}
private static final Set<PropertyId> propertyIds = new HashSet<PropertyId>();
@@ -137,7 +162,7 @@ public class ClusterControllerImplTest {
public void testGetResources() {
ClusterController controller = new ClusterControllerImpl(schemas);
- Request request = new RequestImpl(propertyIds);
+ Request request = new RequestImpl(propertyIds, null);
Iterable<Resource> iterable = controller.getResources(Resource.Type.Host, request, null);
@@ -153,7 +178,7 @@ public class ClusterControllerImplTest {
public void testGetResourcesWithPredicate() {
ClusterController controller = new ClusterControllerImpl(schemas);
- Request request = new RequestImpl(propertyIds);
+ Request request = new RequestImpl(propertyIds, null);
Predicate predicate = new PredicateBuilder().property("p2", "c1").equals(1).toPredicate();
@@ -166,6 +191,17 @@ public class ClusterControllerImplTest {
}
Assert.assertEquals(2, cnt);
}
+
+ @Test
+ public void testGetSchema() {
+ ClusterController controller = new ClusterControllerImpl(schemas);
+
+ Assert.assertSame(hostSchema, controller.getSchema(Resource.Type.Host));
+ Assert.assertSame(serviceSchema, controller.getSchema(Resource.Type.Service));
+ Assert.assertSame(clusterSchema, controller.getSchema(Resource.Type.Cluster));
+ Assert.assertSame(componentSchema, controller.getSchema(Resource.Type.Component));
+ Assert.assertSame(hostComponentSchema, controller.getSchema(Resource.Type.HostComponent));
+ }
}
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/RequestImplTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/RequestImplTest.java Mon Oct 1 18:22:52 2012
@@ -43,7 +43,7 @@ public class RequestImplTest {
@Test
public void testGetPropertyIds() {
- Request request = new RequestImpl(propertyIds);
+ Request request = new RequestImpl(propertyIds, null);
Assert.assertEquals(propertyIds, request.getPropertyIds());
}
Modified: 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=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/SchemaImplTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/internal/SchemaImplTest.java Mon Oct 1 18:22:52 2012
@@ -57,6 +57,21 @@ public class SchemaImplTest {
}
@Override
+ public void createResources(Request request) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void updateResources(Request request, Predicate predicate) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public void deleteResources(Predicate predicate) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
public Set<PropertyId> getPropertyIds() {
return resourceProviderProperties;
}
@@ -89,17 +104,17 @@ public class SchemaImplTest {
propertyProviders.add(propertyProvider);
}
- private static final Map<String, PropertyId> keyPropertyIds = new HashMap<String, PropertyId>();
+ private static final Map<Resource.Type, PropertyId> keyPropertyIds = new HashMap<Resource.Type, 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"));
+ keyPropertyIds.put(Resource.Type.Cluster, Properties.getPropertyId("p1", "c1"));
+ keyPropertyIds.put(Resource.Type.Host, Properties.getPropertyId("p2", "c1"));
+ keyPropertyIds.put(Resource.Type.Component, Properties.getPropertyId("p3", "c1"));
}
@Test
public void testGetKeyPropertyId() {
- Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+ Schema schema = new SchemaImpl(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));
@@ -108,7 +123,7 @@ public class SchemaImplTest {
@Test
public void testGetCategories() {
- Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+ Schema schema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
Map<String, Set<String>> categories = schema.getCategories();
Assert.assertEquals(4, categories.size());
@@ -140,14 +155,14 @@ public class SchemaImplTest {
@Test
public void testGetResourceProvider() {
- Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+ Schema schema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
Assert.assertSame(resourceProvider, schema.getResourceProvider());
}
@Test
public void testGetPropertyProviders() {
- Schema schema = new SchemaImpl(Resource.Type.HostComponent, resourceProvider, propertyProviders, keyPropertyIds);
+ Schema schema = new SchemaImpl(resourceProvider, propertyProviders, keyPropertyIds);
Assert.assertSame(propertyProviders, schema.getPropertyProviders());
}
Added: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jdbc/JDBCManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jdbc/JDBCManagementControllerTest.java?rev=1392497&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jdbc/JDBCManagementControllerTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jdbc/JDBCManagementControllerTest.java Mon Oct 1 18:22:52 2012
@@ -0,0 +1,170 @@
+/**
+ * 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.jdbc;
+
+import org.apache.ambari.api.controller.internal.RequestImpl;
+import org.apache.ambari.api.controller.spi.Predicate;
+import org.apache.ambari.api.controller.spi.PropertyId;
+import org.apache.ambari.api.controller.spi.Request;
+import org.apache.ambari.api.controller.utilities.PredicateBuilder;
+import org.apache.ambari.api.controller.utilities.Properties;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ *
+ */
+public class JDBCManagementControllerTest {
+
+ @Test
+ public void testCreateCluster() throws Exception {
+ ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+ Connection connection = createNiceMock(Connection.class);
+ Statement statement = createNiceMock(Statement.class);
+
+ expect(connectionFactory.getConnection()).andReturn(connection).once();
+ expect(connection.createStatement()).andReturn(statement).once();
+ expect(statement.execute("insert into Clusters (state, version, cluster_name) values ('initial', '1.0', 'MyCluster')")).andReturn(true).once();
+
+ replay(connectionFactory, connection, statement);
+
+ JDBCManagementController provider = new JDBCManagementController(connectionFactory);
+
+ Map<PropertyId, String> properties = new HashMap<PropertyId, String>();
+
+ PropertyId id = Properties.getPropertyId("cluster_name", "Clusters");
+ properties.put(id, "MyCluster");
+
+ id = Properties.getPropertyId("version", "Clusters");
+ properties.put(id, "1.0");
+
+ id = Properties.getPropertyId("state", "Clusters");
+ properties.put(id, "initial");
+
+ Set<Map<PropertyId, String>> propertySet = new HashSet<Map<PropertyId, String>>();
+ propertySet.add(properties);
+
+ Request request = new RequestImpl(null, propertySet);
+
+ provider.createClusters(request);
+
+ verify(connectionFactory, connection, statement);
+ }
+
+ @Test
+ public void testCreateService() throws Exception{
+
+ ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+ Connection connection = createNiceMock(Connection.class);
+ Statement statement = createNiceMock(Statement.class);
+
+ expect(connectionFactory.getConnection()).andReturn(connection).once();
+ expect(connection.createStatement()).andReturn(statement).once();
+ expect(statement.execute("insert into ServiceInfo (service_name, cluster_name, state) values ('MyService', 'MyCluster', 'initial')")).andReturn(true).once();
+
+ replay(connectionFactory, connection, statement);
+
+ JDBCManagementController provider = new JDBCManagementController(connectionFactory);
+
+ Map<PropertyId, String> properties = new HashMap<PropertyId, String>();
+
+ PropertyId id = Properties.getPropertyId("cluster_name", "ServiceInfo");
+ properties.put(id, "MyCluster");
+
+ id = Properties.getPropertyId("service_name", "ServiceInfo");
+ properties.put(id, "MyService");
+
+ id = Properties.getPropertyId("state", "ServiceInfo");
+ properties.put(id, "initial");
+
+ Set<Map<PropertyId, String>> propertySet = new HashSet<Map<PropertyId, String>>();
+ propertySet.add(properties);
+
+ Request request = new RequestImpl(null, propertySet);
+
+ provider.createServices(request);
+
+ verify(connectionFactory, connection, statement);
+ }
+
+ @Test
+ public void testDeleteCluster() throws Exception{
+
+ ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+ Connection connection = createNiceMock(Connection.class);
+ Statement statement = createNiceMock(Statement.class);
+
+ expect(connectionFactory.getConnection()).andReturn(connection).once();
+ expect(connection.createStatement()).andReturn(statement).once();
+ expect(statement.execute("delete from Clusters where Clusters.cluster_name = \"MyCluster\"")).andReturn(true).once();
+
+ replay(connectionFactory, connection, statement);
+
+ JDBCManagementController provider = new JDBCManagementController(connectionFactory);
+
+ Predicate predicate = new PredicateBuilder().property("cluster_name", "Clusters").equals("MyCluster").toPredicate();
+
+ provider.deleteServices(predicate);
+
+ verify(connectionFactory, connection, statement);
+ }
+
+ @Test
+ public void testUpdateCluster() throws Exception{
+
+ ConnectionFactory connectionFactory = createNiceMock(ConnectionFactory.class);
+ Connection connection = createNiceMock(Connection.class);
+ Statement statement = createNiceMock(Statement.class);
+
+ expect(connectionFactory.getConnection()).andReturn(connection).once();
+ expect(connection.createStatement()).andReturn(statement).once();
+ expect(statement.execute("update Clusters set state = 'running' where Clusters.cluster_name = \"MyCluster\"")).andReturn(true).once();
+
+ replay(connectionFactory, connection, statement);
+
+ JDBCManagementController provider = new JDBCManagementController(connectionFactory);
+
+ Map<PropertyId, String> properties = new HashMap<PropertyId, String>();
+
+ PropertyId id = Properties.getPropertyId("state", "Clusters");
+ properties.put(id, "running");
+
+ Predicate predicate = new PredicateBuilder().property("cluster_name", "Clusters").equals("MyCluster").toPredicate();
+
+ Set<Map<PropertyId, String>> propertySet = new HashSet<Map<PropertyId, String>>();
+ propertySet.add(properties);
+
+ Request request = new RequestImpl(null, propertySet);
+
+ provider.updateClusters(request, predicate);
+
+ verify(connectionFactory, connection, statement);
+ }
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/jdbc/JDBCManagementControllerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/utilities/PropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/utilities/PropertiesTest.java?rev=1392497&r1=1392496&r2=1392497&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/utilities/PropertiesTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-api/src/test/java/org/apache/ambari/api/controller/utilities/PropertiesTest.java Mon Oct 1 18:22:52 2012
@@ -19,6 +19,7 @@ package org.apache.ambari.api.controller
import org.apache.ambari.api.controller.spi.PropertyId;
import org.apache.ambari.api.controller.spi.Resource;
+import org.junit.Ignore;
import org.junit.Test;
import java.util.Map;
@@ -29,26 +30,30 @@ import java.util.Set;
*/
public class PropertiesTest {
+ @Ignore
@Test
public void testGetPropertyIds() throws Exception {
Set<PropertyId> propertyIds = Properties.getPropertyIds(Resource.Type.HostComponent, "DB");
+ System.out.println("DB");
for (PropertyId propertyId : propertyIds) {
-// System.out.println(propertyId);
+ System.out.println(propertyId);
}
propertyIds = Properties.getPropertyIds(Resource.Type.HostComponent, "JMX");
+ System.out.println("JMX");
for (PropertyId propertyId : propertyIds) {
-// System.out.println(propertyId);
+ System.out.println(propertyId);
}
propertyIds = Properties.getPropertyIds(Resource.Type.HostComponent, "GANGLIA");
+ System.out.println("GANGLIA");
for (PropertyId propertyId : propertyIds) {
-// System.out.println(propertyId);
+ System.out.println(propertyId);
}
}
@@ -56,7 +61,7 @@ public class PropertiesTest {
@Test
public void testGetKeyPropertyIds() throws Exception {
- Map<String, PropertyId> keyProperties = Properties.getKeyPropertyIds(Resource.Type.Service);
+ Map<Resource.Type, PropertyId> keyProperties = Properties.getKeyPropertyIds(Resource.Type.Service);
System.out.println(keyProperties);
}