incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1400791 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/java/org/apache/ambari/server/api/resources/ ambari-server/src/main/java/org/apache/ambari/server/api/services/ ambari-server/src/main/java/org/apache/ambari/ser...
Date Mon, 22 Oct 2012 07:53:14 GMT
Author: mahadev
Date: Mon Oct 22 07:53:13 2012
New Revision: 1400791

URL: http://svn.apache.org/viewvc?rev=1400791&view=rev
Log:
AMBARI-887. Ability to save configuration. (Nate Cole via mahadev)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntityPK.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ConfigurationRequest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceProviderImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Config.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/META-INF/persistence.xml
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/key_properties.json
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/properties.json

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=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Mon Oct 22 07:53:13 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-887. Ability to save configuration. (Nate Cole via mahadev)
+
   AMBARI-877. Refactor resource provider implementation for changes to
   management interface. (Tom Beerbower via mahadev)
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java Mon Oct 22 07:53:13 2012
@@ -18,11 +18,12 @@
 
 package org.apache.ambari.server.api.resources;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.ambari.server.controller.spi.PropertyId;
 import org.apache.ambari.server.controller.spi.Resource;
 
-import java.util.*;
-
 /**
  * Cluster resource definition.
  */
@@ -67,6 +68,12 @@ public class ClusterResourceDefinition e
         Resource.Type.Host).getKeyPropertyId(Resource.Type.Host);
     hostResource.getQuery().addProperty(hostIdProperty);
     mapChildren.put(hostResource.getPluralName(), hostResource);
+    
+    ConfigurationResourceDefinition configResource = new ConfigurationResourceDefinition(null, null, getId());
+    PropertyId configIdProperty = getClusterController().getSchema(
+        Resource.Type.Configuration).getKeyPropertyId(Resource.Type.Configuration);
+    configResource.getQuery().addProperty(configIdProperty);
+    mapChildren.put(configResource.getPluralName(), configResource);
 
     return mapChildren;
   }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java?rev=1400791&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java Mon Oct 22 07:53:13 2012
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.resources;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+/**
+ * Service resource definition.
+ */
+public class ConfigurationResourceDefinition extends BaseResourceDefinition {
+
+  /**
+   * value of cluster id foreign key
+   */
+  private String m_clusterId;
+
+  /**
+   * Constructor.
+   *
+   * @param id        service id value
+   * @param clusterId cluster id value
+   */
+  public ConfigurationResourceDefinition(String configType, String configTag, String clusterId) {
+    super(Resource.Type.Configuration, configType);
+    m_clusterId = clusterId;
+    setResourceId(Resource.Type.Cluster, m_clusterId);
+    
+    if (null != configTag)
+      setProperty(PropertyHelper.getPropertyId("tag", "Config"), configTag);
+  }
+
+  @Override
+  public String getPluralName() {
+    return "configurations";
+  }
+
+  @Override
+  public String getSingularName() {
+    return "configuration";
+  }
+
+  @Override
+  public Map<String, ResourceDefinition> getSubResources() {
+    return new HashMap<String, ResourceDefinition>();
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java Mon Oct 22 07:53:13 2012
@@ -138,6 +138,14 @@ public class ClusterService extends Base
   public ServiceService getServiceHandler(@PathParam("clusterName") String clusterName) {
     return new ServiceService(clusterName);
   }
+  
+  /**
+   * Gets the configurations sub-resource.
+   */
+  @Path("{clusterName}/configurations")
+  public ConfigurationService getConfigurationHandler(@PathParam("clusterName") String cluster) {
+    return new ConfigurationService(cluster);
+  }
 
   /**
    * Create a cluster resource definition.

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java?rev=1400791&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java Mon Oct 22 07:53:13 2012
@@ -0,0 +1,152 @@
+/**
+ * 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.server.api.services;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ConfigurationResourceDefinition;
+import org.apache.ambari.server.api.resources.ResourceDefinition;
+
+/**
+ * Service responsible for services resource requests.
+ */
+public class ConfigurationService extends BaseService {
+  /**
+   * Parent cluster name.
+   */
+  private String m_clusterName;
+
+  /**
+   * Constructor.
+   *
+   * @param clusterName cluster id
+   */
+  public ConfigurationService(String clusterName) {
+    m_clusterName = clusterName;
+  }
+
+  /**
+   * Handles URL: /clusters/{clusterId}/configurations
+   * Get all services for a cluster.
+   *
+   * @param headers http headers
+   * @param ui      uri info
+   * @return service collection resource representation
+   */
+  @GET
+  @Produces("text/plain")
+  public Response getConfigurations(@Context HttpHeaders headers, @Context UriInfo ui) {
+    return handleRequest(headers, null, ui, Request.Type.GET,
+        createResourceDefinition(null, null, m_clusterName));
+  }  
+
+  /**
+   * Handles URL: /clusters/{clusterId}/configurations
+   * Get all services for a cluster.
+   *
+   * @param headers http headers
+   * @param ui      uri info
+   * @return service collection resource representation
+   */
+  @PUT
+  @Produces("text/plain")
+  public Response createConfigurations(String body,@Context HttpHeaders headers, @Context UriInfo ui) {
+    
+    return handleRequest(headers, body, ui, Request.Type.PUT,
+        createResourceDefinition(null, null, m_clusterName));
+  }    
+  
+  /*
+   * Handles URL: /clusters/{clusterID}/configurations/{configType}
+   * Get a specific service.
+   *
+   * @param headers     http headers
+   * @param ui          uri info
+   * @param configType service id
+   * @return service resource representation
+  
+  @GET
+  @Path("{configType}")
+  @Produces("text/plain")
+  public Response getService(@Context HttpHeaders headers, @Context UriInfo ui,
+                             @PathParam("configType") String configType) {
+
+    return handleRequest(headers, null, ui, Request.Type.GET,
+        createResourceDefinition(configType, null, m_clusterName));
+  }
+   */
+  
+  /*
+   * Handles URL: /clusters/{clusterId}/configurations/{configType}/{configTag}
+   *
+  @GET
+  @Path("{configType}/{configTag}")
+  @Produces("text/plain")
+  public Response getConfig(@Context HttpHeaders headers, @Context UriInfo ui,
+                             @PathParam("configType") String configType,
+                             @PathParam("configTag") String configTag) {
+    return handleRequest(headers, null, ui, Request.Type.GET,
+        createResourceDefinition(configType, configTag, m_clusterName));    
+  }
+   */
+
+
+
+  /*
+   * Handles: PUT /clusters/{clusterId}/configurations/{configType}
+   * Create a specific service.
+   *
+   * @param body        http body
+   * @param headers     http headers
+   * @param ui          uri info
+   * @param serviceName service id
+   * @return information regarding the created service
+   *
+  @PUT
+  @Path("{configType}")
+  @Produces("text/plain")
+  public Response createConfig(String body, @Context HttpHeaders headers, @Context UriInfo ui,
+                                @PathParam("configType") String configType) {
+
+    return handleRequest(headers, body, ui, Request.Type.PUT,
+        createResourceDefinition(configType, null, m_clusterName));
+  }
+  
+   */
+
+
+  /**
+   * Create a service resource definition.
+   *
+   * @param serviceName host name
+   * @param clusterName cluster name
+   * @return a service resource definition
+   */
+  ResourceDefinition createResourceDefinition(String configType, String configTag, String clusterName) {
+    return new ConfigurationResourceDefinition(configType, configTag, clusterName);
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java Mon Oct 22 07:53:13 2012
@@ -77,6 +77,17 @@ public interface AmbariManagementControl
    */
   public void createHostComponents(
       Set<ServiceComponentHostRequest> request) throws AmbariException;
+  
+  /**
+   * Creates a configuration.
+   * 
+   * @param request the request object which defines the configuration.
+   * 
+   * @return a track action response
+   * 
+   * @throws AmbariException when the configuration cannot be created.
+   */
+  public TrackActionResponse createConfiguration(ConfigurationRequest request) throws AmbariException;
 
 
   // ----- Read -------------------------------------------------------------
@@ -141,6 +152,17 @@ public interface AmbariManagementControl
    */
   public Set<ServiceComponentHostResponse> getHostComponents(
       ServiceComponentHostRequest request) throws AmbariException;
+  
+  /**
+   * Gets the configurations identified by the given request object.
+   * 
+   * @param request   the request object
+   * 
+   * @return  a set of configuration responses
+   * 
+   * @throws AmbariException if the configurations could not be read
+   */
+  public Set<ConfigurationResponse> getConfigurations(ConfigurationRequest request) throws AmbariException;
 
 
   // ----- Update -----------------------------------------------------------

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Mon Oct 22 07:53:13 2012
@@ -18,7 +18,15 @@
 
 package org.apache.ambari.server.controller;
 
-import com.google.inject.Injector;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.Role;
@@ -29,7 +37,20 @@ import org.apache.ambari.server.actionma
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
 import org.apache.ambari.server.stageplanner.RoleGraph;
-import org.apache.ambari.server.state.*;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.ConfigFactory;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentFactory;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostFactory;
+import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.StackVersion;
+import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
@@ -37,17 +58,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.inject.Inject;
+import com.google.inject.Injector;
 import com.google.inject.Singleton;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeMap;
-
 @Singleton
 public class AmbariManagementControllerImpl implements
     AmbariManagementController {
@@ -75,6 +87,8 @@ public class AmbariManagementControllerI
   private ServiceComponentFactory serviceComponentFactory;
   @Inject
   private ServiceComponentHostFactory serviceComponentHostFactory;
+  @Inject
+  private ConfigFactory configFactory;
 
   @Inject
   public AmbariManagementControllerImpl(ActionManager actionManager,
@@ -646,6 +660,37 @@ public class AmbariManagementControllerI
     }
 
   }
+  
+  
+  public TrackActionResponse createConfiguration(ConfigurationRequest request) throws AmbariException {
+    if (null == request.getClusterName() || request.getClusterName().isEmpty() ||
+        null == request.getType() || request.getType().isEmpty() ||
+        null == request.getVersionTag() || request.getVersionTag().isEmpty() ||
+        null == request.getConfigs() || request.getConfigs().isEmpty()) {
+      throw new AmbariException ("Invalid Arguments.");
+    }
+      
+    Cluster cluster = clusters.getCluster(request.getClusterName());
+      
+    Map<String, Config> configs = cluster.getDesiredConfigsByType(request.getType());
+    if (null == configs) {
+      configs = new HashMap<String, Config>();
+    }
+    
+    Config config = configs.get(request.getVersionTag());
+    if (configs.containsKey(request.getVersionTag()))
+      throw new AmbariException("Configuration with that tag exists for '" + request.getType() + "'");
+    
+    config = configFactory.createNew (cluster, request.getType(), request.getConfigs());
+    config.setVersionTag(request.getVersionTag());
+    
+    config.persist();
+    
+    cluster.addDesiredConfig(config);
+    
+    // TODO
+    return null;
+  }
 
   private Stage createNewStage(Cluster cluster, long requestId) {
     String logDir = baseLogDir + "/" + requestId;
@@ -947,6 +992,45 @@ public class AmbariManagementControllerI
     return response;
   }
 
+  
+  @Override
+  public Set<ConfigurationResponse> getConfigurations(ConfigurationRequest request) throws AmbariException {
+    if (request.getClusterName() == null) {
+      throw new AmbariException("Invalid arguments");
+    }
+    
+    Cluster cluster = clusters.getCluster(request.getClusterName());
+    
+    Set<ConfigurationResponse> responses = new HashSet<ConfigurationResponse>();
+
+    // !!! if only one, then we need full properties
+    if (null != request.getType() && null != request.getVersionTag()) {
+      Config config = cluster.getDesiredConfig(request.getType(), request.getVersionTag());
+      if (null != config) {
+        ConfigurationResponse response = new ConfigurationResponse(
+            cluster.getClusterName(), config.getType(), config.getVersionTag(),
+            config.getProperties());
+        responses.add(response);
+      }
+    }
+    else {
+      if (null != request.getType()) {
+        Map<String, Config> configs = cluster.getDesiredConfigsByType(request.getType());
+        
+        for (Entry<String, Config> entry : configs.entrySet()) {
+          ConfigurationResponse response = new ConfigurationResponse(
+              cluster.getClusterName(), request.getType(),
+              entry.getValue().getVersionTag(), new HashMap<String, String>());
+          responses.add(response);
+        }
+      }
+    }
+    
+    return responses;
+
+  }
+  
+
   @Override
   public TrackActionResponse updateCluster(ClusterRequest request)
       throws AmbariException {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ConfigurationRequest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ConfigurationRequest.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ConfigurationRequest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ConfigurationRequest.java Mon Oct 22 07:53:13 2012
@@ -30,18 +30,19 @@ public class ConfigurationRequest {
 
   private String type;
 
-  private String versionTag;
+  private String tag;
 
   private Map<String, String> configs;
 
   public ConfigurationRequest(String clusterName,
-                              String type, String versionTag,
+                              String type,
+                              String tag,
                               Map<String, String> configs) {
     super();
     this.clusterName = clusterName;
     this.configs = configs;
     this.type = type;
-    this.versionTag = versionTag;
+    this.tag = tag;
     this.configs = configs;
   }
 
@@ -63,14 +64,14 @@ public class ConfigurationRequest {
    * @return the versionTag
    */
   public String getVersionTag() {
-    return versionTag;
+    return tag;
   }
 
   /**
    * @param versionTag the versionTag to set
    */
   public void setVersionTag(String versionTag) {
-    this.versionTag = versionTag;
+    this.tag = versionTag;
   }
 
   /**

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java Mon Oct 22 07:53:13 2012
@@ -64,6 +64,7 @@ public class ControllerModule extends Ab
     install(new FactoryModuleBuilder().implement(Service.class, ServiceImpl.class).build(ServiceFactory.class));
     install(new FactoryModuleBuilder().implement(ServiceComponent.class, ServiceComponentImpl.class).build(ServiceComponentFactory.class));
     install(new FactoryModuleBuilder().implement(ServiceComponentHost.class, ServiceComponentHostImpl.class).build(ServiceComponentHostFactory.class));
+    install(new FactoryModuleBuilder().implement(Config.class, ConfigImpl.class).build(ConfigFactory.class));
 
     bind(Gson.class).in(Scopes.SINGLETON);
     bind(Clusters.class).to(ClustersImpl.class);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java Mon Oct 22 07:53:13 2012
@@ -91,6 +91,7 @@ public class ClusterControllerImpl imple
       resources = provider.getResources(request, predicate);
       resources = populateResources(type, resources, request, predicate);
     }
+    
     return new ResourceIterable(resources, predicate);
   }
 
@@ -176,12 +177,14 @@ public class ClusterControllerImpl imple
     resourceProviders.put(Resource.Type.Host, providerModule.getResourceProvider(Resource.Type.Host));
     resourceProviders.put(Resource.Type.Component, providerModule.getResourceProvider(Resource.Type.Component));
     resourceProviders.put(Resource.Type.HostComponent, providerModule.getResourceProvider(Resource.Type.HostComponent));
+    resourceProviders.put(Resource.Type.Configuration, providerModule.getResourceProvider(Resource.Type.Configuration));
 
     propertyProviders.put(Resource.Type.Cluster, providerModule.getPropertyProviders(Resource.Type.Cluster));
     propertyProviders.put(Resource.Type.Service, providerModule.getPropertyProviders(Resource.Type.Service));
     propertyProviders.put(Resource.Type.Host, providerModule.getPropertyProviders(Resource.Type.Host));
     propertyProviders.put(Resource.Type.Component, providerModule.getPropertyProviders(Resource.Type.Component));
     propertyProviders.put(Resource.Type.HostComponent, providerModule.getPropertyProviders(Resource.Type.HostComponent));
+    propertyProviders.put(Resource.Type.Configuration, providerModule.getPropertyProviders(Resource.Type.Configuration));
   }
 
 
@@ -289,6 +292,7 @@ public class ClusterControllerImpl imple
     private Resource getNextResource() {
       while (iterator.hasNext()) {
         Resource next = iterator.next();
+        
         if (predicate == null || predicate.evaluate(next)) {
           return next;
         }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java Mon Oct 22 07:53:13 2012
@@ -120,8 +120,7 @@ public class DefaultProviderModule imple
     resourceProviders.put( type , ResourceProviderImpl.getResourceProvider(
         type,
         PropertyHelper.getPropertyIds(type, "DB"),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController));
+        PropertyHelper.getKeyPropertyIds(type), managementController));
   }
 
   private void createPropertyProviders(Resource.Type type) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceProviderImpl.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceProviderImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceProviderImpl.java Mon Oct 22 07:53:13 2012
@@ -18,10 +18,21 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.ClusterRequest;
 import org.apache.ambari.server.controller.ClusterResponse;
+import org.apache.ambari.server.controller.ConfigurationRequest;
+import org.apache.ambari.server.controller.ConfigurationResponse;
 import org.apache.ambari.server.controller.HostRequest;
 import org.apache.ambari.server.controller.HostResponse;
 import org.apache.ambari.server.controller.ServiceComponentHostRequest;
@@ -38,13 +49,6 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * Basic resource provider implementation that maps to a management controller.
  */
@@ -96,6 +100,10 @@ public abstract class ResourceProviderIm
   protected static final PropertyId HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("component_name", "HostRoles");
   protected static final PropertyId HOST_COMPONENT_HOST_NAME_PROPERTY_ID      = PropertyHelper.getPropertyId("host_name", "HostRoles");
   protected static final PropertyId HOST_COMPONENT_STATE_PROPERTY_ID          = PropertyHelper.getPropertyId("state", "HostRoles");
+  // Configurations (values are part of query strings and body post, so they don't have defined categories)
+  protected static final PropertyId CONFIGURATION_CLUSTER_NAME_PROPERTY_ID    = PropertyHelper.getPropertyId("cluster_name","Config");
+  protected static final PropertyId CONFIGURATION_CONFIG_TYPE_PROPERTY_ID     = PropertyHelper.getPropertyId("type");
+  protected static final PropertyId CONFIGURATION_CONFIG_TAG_PROPERTY_ID      = PropertyHelper.getPropertyId("tag");
 
 
   // ----- Constructors ------------------------------------------------------
@@ -272,8 +280,12 @@ public abstract class ResourceProviderIm
         return new HostResourceProvider(propertyIds, keyPropertyIds, managementController);
       case HostComponent:
         return new HostComponentResourceProvider(propertyIds, keyPropertyIds, managementController);
+      case Configuration:
+        return new ConfigurationResourceProvider(propertyIds, keyPropertyIds, managementController);
+      default:
+        throw new IllegalArgumentException("Unknown type " + type);
     }
-    throw new IllegalArgumentException("Unknown type " + type);
+    
   }
 
 
@@ -759,4 +771,108 @@ public abstract class ResourceProviderIm
           (String) properties.get(HOST_COMPONENT_STATE_PROPERTY_ID));
     }
   }
+  
+  /**
+   * Resource provider for configuration resources.
+   */
+  private static class ConfigurationResourceProvider extends ResourceProviderImpl {
+    
+    private static Set<PropertyId> pkPropertyIds =
+        new HashSet<PropertyId>(Arrays.asList(new PropertyId[]{
+            CONFIGURATION_CLUSTER_NAME_PROPERTY_ID,
+            CONFIGURATION_CONFIG_TYPE_PROPERTY_ID }));
+    
+    private ConfigurationResourceProvider(Set<PropertyId> propertyIds,
+        Map<Resource.Type, PropertyId> keyPropertyIds,
+        AmbariManagementController managementController) {
+    
+      super(propertyIds, keyPropertyIds, managementController);
+      
+    }
+
+    @Override
+    public void createResources(Request request) throws AmbariException {
+      for (Map<PropertyId, Object> map : request.getProperties()) {
+        
+        String cluster = (String) map.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID);
+        String type = (String) map.get(PropertyHelper.getPropertyId("type", ""));
+        String tag = (String) map.get(PropertyHelper.getPropertyId("tag", ""));
+        Map<String, String> configMap = new HashMap<String, String>();
+        
+        Iterator<Entry<PropertyId, Object>> it1 = map.entrySet().iterator();
+        while (it1.hasNext()) {
+          Entry<PropertyId, Object> entry = it1.next();
+          if (entry.getKey().getCategory().equals("properties") && null != entry.getValue()) {
+            configMap.put(entry.getKey().getName(), entry.getValue().toString());
+          }
+        }
+        
+        ConfigurationRequest configRequest = new ConfigurationRequest(cluster, type, tag, configMap);
+        
+        getManagementController().createConfiguration(configRequest);
+      }
+      
+    }
+
+    @Override
+    public Set<Resource> getResources(Request request, Predicate predicate)
+        throws AmbariException {
+      
+      ConfigurationRequest configRequest = getRequest(getProperties(predicate));
+
+      Set<ConfigurationResponse> responses = getManagementController().getConfigurations(configRequest);
+
+      Set<Resource> resources = new HashSet<Resource>();
+      for (ConfigurationResponse response : responses) {
+        Resource resource = new ResourceImpl(Resource.Type.Configuration);
+        resource.setProperty(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID, response.getClusterName());
+        resource.setProperty(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID, response.getType());
+        resource.setProperty(CONFIGURATION_CONFIG_TAG_PROPERTY_ID, response.getVersionTag());
+        if (null != response.getConfigs() && response.getConfigs().size() > 0) {
+          Map<String, String> configs = response.getConfigs();
+          
+          for (Entry<String, String> entry : configs.entrySet()) {
+            PropertyId id = PropertyHelper.getPropertyId(entry.getKey(), "properties");
+            resource.setProperty(id, entry.getValue());
+          }
+        }              
+
+        resources.add(resource);
+      }
+      return resources;
+      
+    }
+
+    /**
+     * Throws an exception, as Configurations cannot be updated.
+     */
+    @Override
+    public void updateResources(Request request, Predicate predicate)
+        throws AmbariException {
+      throw new AmbariException ("Cannot update a Configuration resource.");
+    }
+
+    /**
+     * Throws an exception, as Configurations cannot be deleted.
+     */
+    @Override
+    public void deleteResources(Predicate predicate) throws AmbariException {
+      throw new AmbariException ("Cannot delete a Configuration resource.");
+    }
+
+    @Override
+    protected Set<PropertyId> getPKPropertyIds() {
+      return pkPropertyIds;
+    }
+    
+    private ConfigurationRequest getRequest(Map<PropertyId, Object> properties) {
+      String type = (String) properties.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID);
+      
+      String tag = (String) properties.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID);
+      
+      return new ConfigurationRequest(
+          (String) properties.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID),
+          type, tag, new HashMap<String, String>());
+    }
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java Mon Oct 22 07:53:13 2012
@@ -18,13 +18,23 @@
 
 package org.apache.ambari.server.controller.jdbc;
 
-import org.apache.ambari.server.controller.internal.PropertyIdImpl;
-import org.apache.ambari.server.controller.internal.ResourceImpl;
-import org.apache.ambari.server.controller.utilities.PropertyHelper;
+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;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.ClusterRequest;
 import org.apache.ambari.server.controller.ClusterResponse;
+import org.apache.ambari.server.controller.ConfigurationRequest;
+import org.apache.ambari.server.controller.ConfigurationResponse;
 import org.apache.ambari.server.controller.HostRequest;
 import org.apache.ambari.server.controller.HostResponse;
 import org.apache.ambari.server.controller.ServiceComponentHostRequest;
@@ -34,6 +44,8 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.ServiceRequest;
 import org.apache.ambari.server.controller.ServiceResponse;
 import org.apache.ambari.server.controller.TrackActionResponse;
+import org.apache.ambari.server.controller.internal.PropertyIdImpl;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.predicate.AndPredicate;
 import org.apache.ambari.server.controller.predicate.BasePredicate;
 import org.apache.ambari.server.controller.predicate.EqualsPredicate;
@@ -43,17 +55,7 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
-
-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;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
 
 /**
  * Generic JDBC implementation of a management controller.
@@ -98,6 +100,13 @@ public class JDBCManagementController im
   public void createCluster(ClusterRequest request) throws AmbariException {
 //    createResources(Resource.Type.Cluster, request);
   }
+  
+  @Override
+  public TrackActionResponse createConfiguration(ConfigurationRequest request)
+      throws AmbariException {
+    // TODO Auto-generated method stub
+    return null;
+  }
 
   @Override
   public Set<ClusterResponse> getClusters(ClusterRequest request) throws AmbariException {
@@ -124,6 +133,11 @@ public class JDBCManagementController im
   public Set<ServiceComponentHostResponse> getHostComponents(ServiceComponentHostRequest request) throws AmbariException {
     return null;
   }
+  
+  @Override
+  public Set<ConfigurationResponse> getConfigurations(ConfigurationRequest request) throws AmbariException {
+    return null;
+  }
 
   @Override
   public TrackActionResponse updateCluster(ClusterRequest request) throws AmbariException {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java Mon Oct 22 07:53:13 2012
@@ -64,6 +64,7 @@ public interface Resource {
     Service,
     Host,
     Component,
-    HostComponent
+    HostComponent,
+    Configuration
   }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java Mon Oct 22 07:53:13 2012
@@ -18,19 +18,21 @@
 
 package org.apache.ambari.server.orm.dao;
 
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.persist.Transactional;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.TypedQuery;
+
+import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.eclipse.persistence.jpa.JpaEntityManager;
 
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.TypedQuery;
-import java.util.List;
-import java.util.Set;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.persist.Transactional;
 
 public class ClusterDAO {
   private static final Log log = LogFactory.getLog(ClusterDAO.class);
@@ -74,7 +76,15 @@ public class ClusterDAO {
   public void create(ClusterEntity clusterEntity) {
     entityManagerProvider.get().persist(clusterEntity);
   }
-
+  
+  /**
+   * Creates a cluster configuration in the DB.
+   */
+  @Transactional
+  public void createConfig(ClusterConfigEntity entity) {
+    entityManagerProvider.get().persist(entity);
+  }
+  
   /**
    * Retrieve entity data from DB
    * @param clusterEntity entity to refresh

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java?rev=1400791&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java Mon Oct 22 07:53:13 2012
@@ -0,0 +1,124 @@
+/**
+ * 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.server.orm.entities;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@IdClass(ClusterConfigEntityPK.class)
+@Table(name = "clusterconfig", schema = "ambari", catalog = "")
+@Entity
+public class ClusterConfigEntity {
+  private Long clusterId;
+  private String configJson;
+  private String type;
+  private String tag;
+  private long timestamp;
+  
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
+  @Id
+  public Long getClusterId() {
+    return clusterId;
+  }
+
+  public void setClusterId(Long clusterId) {
+    this.clusterId = clusterId;
+  }
+  
+  @Column(name = "type_name")
+  @Id
+  public String getType() {
+    return type;
+  }
+  
+  public void setType(String typeName) {
+    type = typeName;
+  }
+  
+  @Column(name = "version_tag")
+  @Id
+  public String getTag() {
+    return tag;
+  }
+  
+  public void setTag(String versionTag) {
+    tag = versionTag;
+  }
+
+  @Column(name = "config_data", nullable = false, insertable = true, updatable = false, length=4000)
+  @Basic(fetch=FetchType.LAZY)
+  public String getData() {
+    return configJson;
+  }
+
+  public void setData(String data) {
+    this.configJson = data;
+  }
+  
+  @Column(name = "create_timestamp", nullable=false, insertable=true, updatable=false)
+  public long getTimestamp() {
+    return timestamp;
+  }
+  
+  public void setTimestamp(long stamp) {
+    timestamp = stamp;
+  }
+
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ClusterConfigEntity that = (ClusterConfigEntity) o;
+
+    if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
+    if (configJson != null ? !configJson.equals(that.configJson) : that.configJson != null)
+      return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterId !=null ? clusterId.intValue() : 0;
+    result = 31 * result + (configJson != null ? configJson.hashCode() : 0);
+    return result;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntityPK.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntityPK.java?rev=1400791&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntityPK.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntityPK.java Mon Oct 22 07:53:13 2012
@@ -0,0 +1,82 @@
+/**
+ * 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.server.orm.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class ClusterConfigEntityPK implements Serializable {
+  private Long clusterId;
+
+  @Id
+  @Column(name = "cluster_id", nullable = false, insertable = true, updatable = true, length = 10)
+  public Long getClusterId() {
+    return clusterId;
+  }
+
+  public void setClusterId(Long clusterId) {
+    this.clusterId = clusterId;
+  }
+
+  private String type;
+  @Id
+  @Column(name = "type_name", nullable = false, insertable = true, updatable = false)
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String typeName) {
+    type = typeName;
+  }
+  
+  private String tag;
+  @Id
+  @Column(name="version_tag", nullable = false, insertable = true, updatable = false)
+  public String getTag() {
+    return tag;
+  }
+  
+  public void setTag(String configTag) {
+    tag = configTag;
+  }
+  
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ClusterConfigEntityPK that = (ClusterConfigEntityPK) o;
+
+    if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
+    if (type != null ? !type.equals(that.type) : that.type != null) return false;
+    if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterId !=null ? clusterId.intValue() : 0;
+    result = 31 * result + (type != null ? type.hashCode() : 0);
+    result = 31 * result + (tag != null ? tag.hashCode() : 0);
+    return result;
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java Mon Oct 22 07:53:13 2012
@@ -150,4 +150,14 @@ public class ClusterEntity {
   public void setStages(Collection<StageEntity> stages) {
     this.stages = stages;
   }
+  
+  private Collection<ClusterConfigEntity> configEntities;
+  @OneToMany(mappedBy = "clusterEntity")
+  public Collection<ClusterConfigEntity> getClusterConfigEntities() {
+    return configEntities;
+  }
+  
+  public void setClusterConfigEntities(Collection<ClusterConfigEntity> entities) {
+    configEntities = entities;
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Config.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Config.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Config.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Config.java Mon Oct 22 07:53:13 2012
@@ -64,4 +64,9 @@ public interface Config {
    * @param properties Property keys to be deleted
    */
   public void deleteProperties(List<String> properties);
+  
+  /**
+   * Persist the configuration.
+   */
+  public void persist();
 }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java?rev=1400791&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java Mon Oct 22 07:53:13 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.server.state;
+
+import java.util.Map;
+
+import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
+
+/**
+ * @author ncole
+ *
+ */
+public interface ConfigFactory {
+  
+  Config createNew(Cluster cluster, String type, Map<String, String> map);
+  
+  Config createExisting(Cluster cluster, ClusterConfigEntity entity);
+
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java Mon Oct 22 07:53:13 2012
@@ -19,29 +19,53 @@
 package org.apache.ambari.server.state;
 
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-public class ConfigImpl implements Config {
+import org.apache.ambari.server.orm.dao.ClusterDAO;
+import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
+
+import com.google.gson.Gson;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.assistedinject.Assisted;
+import com.google.inject.assistedinject.AssistedInject;
+import com.google.inject.persist.Transactional;
 
-  private final String type;
+public class ConfigImpl implements Config {
 
+  private Cluster cluster;
+  private String type;
   private String versionTag;
-
   private Map<String, String> properties;
-
-  public ConfigImpl(String type, String versionTag,
-      Map<String, String> properties) {
+  private ClusterConfigEntity entity;
+  
+  @Inject
+  private ClusterDAO clusterDAO;
+  @Inject
+  private Gson gson;
+
+  @AssistedInject
+  public ConfigImpl(@Assisted Cluster cluster, @Assisted String type, @Assisted Map<String, String> properties, Injector injector) {
+    this.cluster = cluster;
     this.type = type;
-    this.versionTag = versionTag;
     this.properties = properties;
+    injector.injectMembers(this);
+    
   }
-
-  public ConfigImpl(String type, String versionTag) {
-    this(type, versionTag, new HashMap<String, String>());
+  
+  @AssistedInject
+  public ConfigImpl(@Assisted Cluster cluster, @Assisted ClusterConfigEntity entity, Injector injector) {
+    this.cluster = cluster;
+    this.type = entity.getType();
+    this.versionTag = entity.getTag();
+    this.entity = entity;
+    injector.injectMembers(this);
   }
-
+  
   @Override
   public String getType() {
     return type;
@@ -54,7 +78,12 @@ public class ConfigImpl implements Confi
 
   @Override
   public synchronized Map<String, String> getProperties() {
-    return Collections.unmodifiableMap(properties);
+    if (null != entity && null == properties) {
+      
+      properties = gson.fromJson(entity.getData(), Map.class);
+      
+    }
+    return Collections.unmodifiableMap(null == properties ? new HashMap<String, String>() : properties);
   }
 
   @Override
@@ -78,6 +107,28 @@ public class ConfigImpl implements Confi
       this.properties.remove(key);
     }
   }
+  
+  @Transactional
+  @Override
+  public void persist() {
+    
+    ClusterEntity clusterEntity = clusterDAO.findById(cluster.getClusterId());
+    
+    ClusterConfigEntity entity = new ClusterConfigEntity();
+    entity.setClusterEntity(clusterEntity);
+    entity.setClusterId(Long.valueOf(cluster.getClusterId()));
+    entity.setType(type);
+    entity.setTag(versionTag);
+    entity.setTimestamp(new Date().getTime());
+    
+    entity.setData(gson.toJson(properties));
+    clusterDAO.createConfig(entity);
+
+    clusterEntity.getClusterConfigEntities().add(entity);
+    clusterDAO.merge(clusterEntity);
+    cluster.refresh();
+    
+  }
 
 
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java Mon Oct 22 07:53:13 2012
@@ -29,21 +29,29 @@ import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.assistedinject.Assisted;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ServiceComponentHostNotFoundException;
 import org.apache.ambari.server.ServiceNotFoundException;
 import org.apache.ambari.server.controller.ClusterResponse;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
-import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
+import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
-import org.apache.ambari.server.state.*;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.ConfigFactory;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.StackVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.assistedinject.Assisted;
+
 public class ClusterImpl implements Cluster {
 
   private static final Logger LOG =
@@ -82,10 +90,12 @@ public class ClusterImpl implements Clus
 
   @Inject
   private ClusterDAO clusterDAO;
-  @Inject
-  private ClusterServiceDAO clusterServiceDAO;
+//  @Inject
+//  private ClusterServiceDAO clusterServiceDAO;
   @Inject
   private ServiceFactory serviceFactory;
+  @Inject
+  private ConfigFactory configFactory;
 
   @Inject
   public ClusterImpl(@Assisted ClusterEntity clusterEntity,
@@ -106,7 +116,23 @@ public class ClusterImpl implements Clus
     this.serviceComponentHostsByHost = new HashMap<String,
         List<ServiceComponentHost>>();
     this.desiredStackVersion = new StackVersion("");
-    this.configs = new HashMap<String, Map<String,Config>>();
+    
+    configs = new HashMap<String, Map<String,Config>>();
+    if (!clusterEntity.getClusterConfigEntities().isEmpty()) {
+      for (ClusterConfigEntity entity : clusterEntity.getClusterConfigEntities()) {
+        
+        if (!configs.containsKey(entity.getType())) {
+          configs.put(entity.getType(), new HashMap<String, Config>());
+        }
+
+        Config config = configFactory.createExisting(this, entity);
+        
+        configs.get(entity.getType()).put(entity.getTag(), config);
+      }
+    }
+      
+    
+    
   }
 
   public ServiceComponentHost getServiceComponentHost(String serviceName,
@@ -288,6 +314,9 @@ public class ClusterImpl implements Clus
 
   @Override
   public synchronized Map<String, Config> getDesiredConfigsByType(String configType) {
+    if (!configs.containsKey(configType))
+      return null;
+
     return Collections.unmodifiableMap(configs.get(configType));
   }
 
@@ -312,9 +341,6 @@ public class ClusterImpl implements Clus
       configs.put(config.getType(), new HashMap<String, Config>());
     }
 
-    // TODO should we check for duplicates and throw an error?
-    // if (configs.get(config.getType()).containsKey(config.getVersionTag()))
-
     configs.get(config.getType()).put(config.getVersionTag(), config);
   }
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/META-INF/persistence.xml?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/META-INF/persistence.xml (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/META-INF/persistence.xml Mon Oct 22 07:53:13 2012
@@ -20,6 +20,7 @@
   <persistence-unit name="ambari-postgres">
     <class>org.apache.ambari.server.orm.entities.ActionStatusEntity</class>
     <class>org.apache.ambari.server.orm.entities.ClusterEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ClusterConfigEntity</class>
     <class>org.apache.ambari.server.orm.entities.ClusterServiceEntity</class>
     <class>org.apache.ambari.server.orm.entities.ClusterStateEntity</class>
     <class>org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity</class>
@@ -50,6 +51,7 @@
   <persistence-unit name="ambari-javadb">
     <class>org.apache.ambari.server.orm.entities.ActionStatusEntity</class>
     <class>org.apache.ambari.server.orm.entities.ClusterEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ClusterConfigEntity</class>
     <class>org.apache.ambari.server.orm.entities.ClusterServiceEntity</class>
     <class>org.apache.ambari.server.orm.entities.ClusterStateEntity</class>
     <class>org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity</class>

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/key_properties.json
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/key_properties.json?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/key_properties.json (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/key_properties.json Mon Oct 22 07:53:13 2012
@@ -63,5 +63,17 @@
       "category":"HostRoles",
       "temporal":false
     }
+  },
+  "Configuration":{
+    "Cluster":{
+      "name":"cluster_name",
+      "category":"Config",
+      "temporal":false
+    },
+    "Configuration":{
+      "name":"type",
+      "category":"Config",
+      "temporal":false
+    }
   }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/properties.json
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/properties.json?rev=1400791&r1=1400790&r2=1400791&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/properties.json (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/properties.json Mon Oct 22 07:53:13 2012
@@ -439,5 +439,29 @@
         "temporal":true
       }
     ]
+  },
+  "Configuration":{
+    "DB":[
+      {
+        "name":"tag",
+        "category":"Config",
+        "temporal":false
+      },
+      {
+      	"name":"type",
+      	"category":"Config",
+      	"temporal":false
+      },
+      {
+        "name":"cluster_name",
+        "category":"Config",
+        "temporal":false
+      }
+    ],
+    "JMX":[
+    ],
+    "GANGLIA":[
+    ]
   }
+
 }



Mime
View raw message