ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smn...@apache.org
Subject ambari git commit: AMBARI-14750: Provide CRUD support for admin settings (Ajit Kumar via Nahappan Somasundaram)
Date Fri, 22 Jan 2016 18:15:37 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 8d329087b -> f2a44a7e1


AMBARI-14750: Provide CRUD support for admin settings (Ajit Kumar via Nahappan Somasundaram)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f2a44a7e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f2a44a7e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f2a44a7e

Branch: refs/heads/trunk
Commit: f2a44a7e101cfdd9ff30abcc2bf36127a7ce75e9
Parents: 8d32908
Author: Nahappan Somasundaram <nsomasundaram@hortonworks.com>
Authored: Fri Jan 22 10:03:13 2016 -0800
Committer: Nahappan Somasundaram <nsomasundaram@hortonworks.com>
Committed: Fri Jan 22 10:15:13 2016 -0800

----------------------------------------------------------------------
 .../resources/ResourceInstanceFactoryImpl.java  |   4 +
 .../api/services/AdminSettingService.java       | 148 ++++++++++++
 .../internal/AdminSettingResourceProvider.java  | 241 +++++++++++++++++++
 .../internal/DefaultProviderModule.java         |   2 +
 .../ambari/server/controller/spi/Resource.java  |  16 +-
 .../ambari/server/orm/dao/AdminSettingDAO.java  | 100 ++++++++
 .../server/orm/entities/AdminSettingEntity.java | 149 ++++++++++++
 .../src/main/resources/META-INF/persistence.xml |   3 +-
 .../AdminSettingResourceProviderTest.java       | 213 ++++++++++++++++
 .../server/orm/dao/AdminSettingDAOTest.java     |  89 +++++++
 .../orm/entities/AdminSettingEntityTest.java    |  91 +++++++
 11 files changed, 1048 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
index c7c5d61..070a505 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
@@ -408,6 +408,10 @@ public class ResourceInstanceFactoryImpl implements ResourceInstanceFactory {
         resourceDefinition = new SimpleResourceDefinition(Resource.Type.UserAuthorization, "authorization", "authorizations");
         break;
 
+      case AdminSetting:
+        resourceDefinition = new SimpleResourceDefinition(Resource.Type.AdminSetting, "admin-setting", "admin-settings");
+        break;
+
       default:
         throw new IllegalArgumentException("Unsupported resource type: " + type);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/java/org/apache/ambari/server/api/services/AdminSettingService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AdminSettingService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AdminSettingService.java
new file mode 100644
index 0000000..2c5b77d
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AdminSettingService.java
@@ -0,0 +1,148 @@
+/**
+ * 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 org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.controller.spi.Resource;
+
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+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 java.util.Collections;
+
+/**
+ * Service responsible for admin setting resource requests.
+ */
+@Path("/admin-settings/")
+public class AdminSettingService extends BaseService {
+
+  /**
+   * Construct a AdminSettingService.
+   */
+  public AdminSettingService() {
+
+  }
+
+  /**
+   * Handles: GET  /settings
+   * Get all clusters.
+   *
+   * @param headers  http headers
+   * @param ui       uri info
+   *
+   * @return admin setting collection resource representation
+   */
+  @GET
+  @Produces("text/plain")
+  public Response getSettings(String body, @Context HttpHeaders headers, @Context UriInfo ui) {
+    return handleRequest(headers, body, ui, Request.Type.GET, createSettingResource(null));
+  }
+
+  /**
+   * Handles: GET /admin-settings/{settingName}
+   * Get a specific admin setting.
+   *
+   * @param headers      http headers
+   * @param ui           uri info
+   * @param settingName  settingName
+   *
+   * @return admin setting instance representation
+   */
+  @GET
+  @Path("{settingName}")
+  @Produces("text/plain")
+  public Response getSetting(String body, @Context HttpHeaders headers, @Context UriInfo ui,
+                             @PathParam("settingName") String settingName) {
+    return handleRequest(headers, body, ui, Request.Type.GET, createSettingResource(settingName));
+  }
+
+  /**
+   * Handles: POST /admin-settings/{settingName}
+   * Create a specific admin setting.
+   *
+   * @param headers      http headers
+   * @param ui           uri info
+   *
+   * @return information regarding the created setting
+   */
+   @POST
+   @Produces("text/plain")
+   public Response createSetting(String body, @Context HttpHeaders headers, @Context UriInfo ui) {
+     return handleRequest(headers, body, ui, Request.Type.POST, createSettingResource(null));
+  }
+
+  /**
+   * Handles: PUT /admin-settings/{settingName}
+   * Update a specific admin setting.
+   *
+   * @param headers      http headers
+   * @param ui           uri info
+   * @param settingName  setting name
+   *
+   * @return information regarding the updated setting
+   */
+  @PUT
+  @Path("{settingName}")
+  @Produces("text/plain")
+  public Response updateSetting(String body, @Context HttpHeaders headers, @Context UriInfo ui,
+                                @PathParam("settingName") String settingName) {
+    return handleRequest(headers, body, ui, Request.Type.PUT, createSettingResource(settingName));
+  }
+
+  /**
+   * Handles: DELETE /admin-settings/{settingName}
+   * Delete a specific admin setting.
+   *
+   * @param headers      http headers
+   * @param ui           uri info
+   * @param settingName  setting name
+   *
+   * @return information regarding the deleted setting
+   */
+  @DELETE
+  @Path("{settingName}")
+  @Produces("text/plain")
+  public Response deleteSetting(@Context HttpHeaders headers, @Context UriInfo ui,
+                                @PathParam("settingName") String settingName) {
+    return handleRequest(headers, null, ui, Request.Type.DELETE, createSettingResource(settingName));
+  }
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create an admin setting resource instance.
+   *
+   * @param settingName setting name
+   *
+   * @return an admin setting resource instance
+   */
+  ResourceInstance createSettingResource(String settingName) {
+    return createResource(Resource.Type.AdminSetting,
+        Collections.singletonMap(Resource.Type.AdminSetting, settingName));
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProvider.java
new file mode 100644
index 0000000..21b0544
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProvider.java
@@ -0,0 +1,241 @@
+/**
+ * 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.controller.internal;
+
+import com.google.inject.Inject;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.StaticallyInject;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.dao.AdminSettingDAO;
+import org.apache.ambari.server.orm.entities.AdminSettingEntity;
+import org.apache.ambari.server.security.authorization.AuthorizationException;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * This class deals with managing CRUD operation on {@link AdminSettingEntity}.
+ */
+@StaticallyInject
+public class AdminSettingResourceProvider extends AbstractAuthorizedResourceProvider {
+  protected static final String ID = "id";
+  protected static final String ADMINSETTING = "AdminSetting";
+  protected static final String ADMINSETTING_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("AdminSettings", "name");
+  protected static final String ADMINSETTING_SETTING_TYPE_PROPERTY_ID = PropertyHelper.getPropertyId("AdminSettings", "setting_type");
+  protected static final String ADMINSETTING_CONTENT_PROPERTY_ID = PropertyHelper.getPropertyId("AdminSettings", "content");
+  protected static final String ADMINSETTING_UPDATED_BY_PROPERTY_ID = PropertyHelper.getPropertyId("AdminSettings", "updated_by");
+  protected static final String ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID = PropertyHelper.getPropertyId("AdminSettings", "update_timestamp");
+
+  /**
+   * The property ids for a admin setting resource.
+   */
+  private static final Set<String> propertyIds = new HashSet<>();
+
+  /**
+   * The key property ids for a admin setting resource.
+   */
+  private static final Map<Resource.Type, String> keyPropertyIds = new HashMap<>();
+
+  private static final Set<String> requiredProperties = new HashSet<>();
+
+  @Inject
+  private static AdminSettingDAO dao;
+
+  static {
+    propertyIds.add(ADMINSETTING_NAME_PROPERTY_ID);
+    propertyIds.add(ADMINSETTING_SETTING_TYPE_PROPERTY_ID);
+    propertyIds.add(ADMINSETTING_CONTENT_PROPERTY_ID);
+    propertyIds.add(ADMINSETTING_UPDATED_BY_PROPERTY_ID);
+    propertyIds.add(ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+    propertyIds.add(ADMINSETTING_SETTING_TYPE_PROPERTY_ID);
+    propertyIds.add(ADMINSETTING);
+
+    keyPropertyIds.put(Resource.Type.AdminSetting, ADMINSETTING_NAME_PROPERTY_ID);
+
+    requiredProperties.add(ADMINSETTING_NAME_PROPERTY_ID);
+    requiredProperties.add(ADMINSETTING_SETTING_TYPE_PROPERTY_ID);
+    requiredProperties.add(ADMINSETTING_CONTENT_PROPERTY_ID);
+  }
+
+  protected AdminSettingResourceProvider() {
+    super(propertyIds, keyPropertyIds);
+  }
+
+  @Override
+  protected Set<String> getPKPropertyIds() {
+    return new HashSet<>(keyPropertyIds.values());
+  }
+
+  //TODO : add RBAC as part of https://issues.apache.org/jira/browse/AMBARI-14728.
+  @Override
+  public RequestStatus createResources(Request request)
+          throws NoSuchParentResourceException, ResourceAlreadyExistsException, SystemException {
+    Set<Resource> associatedResources = new HashSet<>();
+
+    for (Map<String, Object> properties : request.getProperties()) {
+      AdminSettingEntity settingEntity = createResources(newCreateCommand(request, properties));
+      Resource resource = new ResourceImpl(Resource.Type.AdminSetting);
+      resource.setProperty(ADMINSETTING_NAME_PROPERTY_ID, settingEntity.getName());
+      associatedResources.add(resource);
+    }
+
+    return getRequestStatus(null, associatedResources);
+  }
+
+  @Override
+  public Set<Resource> getResources(Request request, Predicate predicate) throws NoSuchResourceException {
+    List<AdminSettingEntity> entities = new LinkedList<>();
+    final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
+    if (propertyMaps.isEmpty()) {
+      entities = dao.findAll();
+    }
+    for (Map<String, Object> propertyMap: propertyMaps) {
+      if (propertyMap.containsKey(ADMINSETTING_NAME_PROPERTY_ID)) {
+        String name = propertyMap.get(ADMINSETTING_NAME_PROPERTY_ID).toString();
+        AdminSettingEntity entity = dao.findByName(name);
+        if (entity == null) {
+          throw new NoSuchResourceException(String.format("AdminSetting with name %s does not exists", name));
+        }
+        entities.add(entity);
+      } else {
+        entities = dao.findAll();
+        break;
+      }
+    }
+    Set<String> requestedIds = getRequestPropertyIds(request, predicate);
+    Set<Resource> resources = new HashSet<>();
+    for(AdminSettingEntity entity : entities) {
+      resources.add(toResource(entity, requestedIds));
+    }
+    return resources;
+  }
+
+  @Override
+  public RequestStatus updateResources(Request request, Predicate predicate)
+          throws NoSuchResourceException, NoSuchParentResourceException, SystemException {
+    modifyResources(newUpdateCommand(request));
+    return getRequestStatus(null);
+  }
+
+  @Override
+  public RequestStatus deleteResources(Predicate predicate) {
+    final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
+    for (Map<String, Object> propertyMap : propertyMaps) {
+      if (propertyMap.containsKey(ADMINSETTING_NAME_PROPERTY_ID)) {
+        dao.removeByName(propertyMap.get(ADMINSETTING_NAME_PROPERTY_ID).toString());
+      }
+    }
+    return getRequestStatus(null);
+  }
+
+
+  private Command<AdminSettingEntity> newCreateCommand(final Request request, final Map<String, Object> properties) {
+    return new Command<AdminSettingEntity>() {
+      @Override
+      public AdminSettingEntity invoke() throws AmbariException, AuthorizationException {
+        AdminSettingEntity entity = toEntity(properties);
+        dao.create(entity);
+        notifyCreate(Resource.Type.AdminSetting, request);
+        return entity;
+      }
+    };
+  }
+
+  private Command<Void> newUpdateCommand(final Request request) throws NoSuchResourceException, SystemException {
+    return new Command<Void>() {
+      @Override
+      public Void invoke() throws AmbariException {
+        final Set<Map<String, Object>> propertyMaps = request.getProperties();
+        for (Map<String, Object> propertyMap : propertyMaps) {
+          if (propertyMap.containsKey(ADMINSETTING_NAME_PROPERTY_ID)) {
+            String name = propertyMap.get(ADMINSETTING_NAME_PROPERTY_ID).toString();
+            AdminSettingEntity entity = dao.findByName(name);
+            if (entity == null) {
+              throw new AmbariException(String.format("There is no admin setting with name: %s ", name));
+            }
+            updateEntity(entity, propertyMap);
+            dao.merge(entity);
+          }
+        }
+        return null;
+      }
+    };
+  }
+
+  private void updateEntity(AdminSettingEntity entity, Map<String, Object> propertyMap) throws AmbariException {
+    String name = propertyMap.get(ADMINSETTING_NAME_PROPERTY_ID).toString();
+    if (!Objects.equals(name, entity.getName())) {
+      throw new AmbariException("Name for AdminSetting is immutable, cannot change name.");
+    }
+
+    if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(ADMINSETTING_CONTENT_PROPERTY_ID)))) {
+      entity.setContent(propertyMap.get(ADMINSETTING_CONTENT_PROPERTY_ID).toString());
+    }
+
+    if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(ADMINSETTING_SETTING_TYPE_PROPERTY_ID)))) {
+      entity.setSettingType(propertyMap.get(ADMINSETTING_SETTING_TYPE_PROPERTY_ID).toString());
+    }
+
+    if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(ADMINSETTING_UPDATED_BY_PROPERTY_ID)))) {
+      entity.setUpdatedBy(propertyMap.get(ADMINSETTING_UPDATED_BY_PROPERTY_ID).toString());
+    }
+
+    entity.setUpdateTimestamp(System.currentTimeMillis());
+  }
+
+  private Resource toResource(final AdminSettingEntity adminSettingEntity, final Set<String> requestedIds) {
+    Resource resource = new ResourceImpl(Resource.Type.AdminSetting);
+    setResourceProperty(resource, ADMINSETTING_NAME_PROPERTY_ID, adminSettingEntity.getName(), requestedIds);
+    setResourceProperty(resource, ADMINSETTING_SETTING_TYPE_PROPERTY_ID, adminSettingEntity.getSettingType(), requestedIds);
+    setResourceProperty(resource, ADMINSETTING_CONTENT_PROPERTY_ID, adminSettingEntity.getContent(), requestedIds);
+    setResourceProperty(resource, ADMINSETTING_UPDATED_BY_PROPERTY_ID, adminSettingEntity.getUpdatedBy(), requestedIds);
+    setResourceProperty(resource, ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID, adminSettingEntity.getUpdateTimestamp(), requestedIds);
+    return resource;
+  }
+
+  private AdminSettingEntity toEntity(final Map<String, Object> properties) throws AmbariException {
+    for (String propertyName: requiredProperties) {
+      if (properties.get(propertyName) == null) {
+        throw new AmbariException(String.format("Property %s should be provided", propertyName));
+      }
+    }
+
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setName(properties.get(ADMINSETTING_NAME_PROPERTY_ID).toString());
+    entity.setSettingType(properties.get(ADMINSETTING_SETTING_TYPE_PROPERTY_ID).toString());
+    entity.setContent(properties.get(ADMINSETTING_CONTENT_PROPERTY_ID).toString());
+    entity.setUpdatedBy(properties.get(ADMINSETTING_UPDATED_BY_PROPERTY_ID).toString());
+    entity.setUpdateTimestamp(System.currentTimeMillis());
+    return entity;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
index 3801cc3..12447f9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
@@ -114,6 +114,8 @@ public class DefaultProviderModule extends AbstractProviderModule {
         return new OperatingSystemResourceProvider(managementController);
       case Repository:
         return new RepositoryResourceProvider(managementController);
+      case AdminSetting:
+        return new AdminSettingResourceProvider();
       case Artifact:
         return new ArtifactResourceProvider(managementController);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
index e367afe..9d6af76 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
@@ -32,7 +32,7 @@ public interface Resource {
    *
    * @return the resource type
    */
-  public Type getType();
+  Type getType();
 
   /**
    * Obtain the properties contained by this group in a map structure.
@@ -42,7 +42,7 @@ public interface Resource {
    *
    * @return resource properties map
    */
-  public Map<String, Map<String, Object>> getPropertiesMap();
+  Map<String, Map<String, Object>> getPropertiesMap();
 
   /**
    * Set a property value for the given property id on this resource.
@@ -50,14 +50,14 @@ public interface Resource {
    * @param id    the property id
    * @param value the value
    */
-  public void setProperty(String id, Object value);
+  void setProperty(String id, Object value);
 
   /**
    * Add an empty category to this resource.
    *
    * @param id the category id
    */
-  public void addCategory(String id);
+  void addCategory(String id);
 
   /**
    * Get a property value for the given property id from this resource.
@@ -65,7 +65,7 @@ public interface Resource {
    * @param id the property id
    * @return the property value
    */
-  public Object getPropertyValue(String id);
+  Object getPropertyValue(String id);
 
 
   // ----- Enum : InternalType -----------------------------------------------
@@ -73,9 +73,10 @@ public interface Resource {
   /**
    * Enum of internal types.
    */
-  public enum InternalType {
+  enum InternalType {
     Cluster,
     Service,
+    AdminSetting,
     Host,
     Component,
     HostComponent,
@@ -169,7 +170,7 @@ public interface Resource {
   /**
    * Resource types.  Allows for the addition of external types.
    */
-  public final class Type implements Comparable<Type>{
+  final class Type implements Comparable<Type>{
 
     /**
      * Map of all registered types.
@@ -186,6 +187,7 @@ public interface Resource {
      */
     public static final Type Cluster = InternalType.Cluster.getType();
     public static final Type Service = InternalType.Service.getType();
+    public static final Type AdminSetting = InternalType.AdminSetting.getType();
     public static final Type Host = InternalType.Host.getType();
     public static final Type Component = InternalType.Component.getType();
     public static final Type HostComponent = InternalType.HostComponent.getType();

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AdminSettingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AdminSettingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AdminSettingDAO.java
new file mode 100644
index 0000000..30e032f
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AdminSettingDAO.java
@@ -0,0 +1,100 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.RequiresSession;
+import org.apache.ambari.server.orm.entities.AdminSettingEntity;
+import org.apache.commons.lang.StringUtils;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+@Singleton
+public class AdminSettingDAO {
+
+  @Inject
+  Provider<EntityManager> entityManagerProvider;
+  @Inject
+  DaoUtils daoUtils;
+
+  /**
+   * Find an admin setting with the given name.
+   *
+   * @param name - name of admin setting.
+   * @return  a matching admin setting or null
+   */
+  @RequiresSession
+  public AdminSettingEntity findByName(String name) {
+    if (StringUtils.isBlank(name)) {
+      return null;
+    }
+    TypedQuery<AdminSettingEntity> query = entityManagerProvider.get()
+            .createNamedQuery("adminSettingByName", AdminSettingEntity.class);
+    query.setParameter("name", name);
+    return daoUtils.selectOne(query);
+  }
+
+  /**
+   * Find all admin settings.
+   *
+   * @return all admin setting instances.
+   */
+  @RequiresSession
+  public List<AdminSettingEntity> findAll() {
+    return daoUtils.selectAll(entityManagerProvider.get(), AdminSettingEntity.class);
+  }
+
+  /**
+   * Create a new admin setting entity.
+   *
+   * @param entity - entity to be created
+   */
+  @Transactional
+  public void create(AdminSettingEntity entity) {
+    entityManagerProvider.get().persist(entity);
+  }
+
+  /**
+   * Update admin setting instance.
+   *
+   * @param entity - entity to be updated.
+   * @return - updated admin entity.
+   */
+  @Transactional
+  public AdminSettingEntity merge(AdminSettingEntity entity) {
+    return entityManagerProvider.get().merge(entity);
+  }
+
+  /**
+   * Delete admin setting with given name.
+   *
+   * @param name - name of admin setting to be deleted.
+   */
+  @Transactional
+  public void removeByName(String name) {
+    AdminSettingEntity entity = findByName(name);
+    if (entity!= null) {
+      entityManagerProvider.get().remove(entity);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AdminSettingEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AdminSettingEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AdminSettingEntity.java
new file mode 100644
index 0000000..9edc7b5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AdminSettingEntity.java
@@ -0,0 +1,149 @@
+/**
+ * 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.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import java.util.Objects;
+
+/**
+ * Entity representing AdminSetting.
+ */
+@Table(name = "adminsetting")
+@TableGenerator(name = "admin_setting_id_generator",
+    table = "ambari_sequences", pkColumnName = "sequence_name", valueColumnName = "sequence_value",
+        pkColumnValue = "admin_setting_id_seq", initialValue = 0)
+
+@NamedQuery(name = "adminSettingByName", query = "SELECT adminSetting FROM AdminSettingEntity adminsetting WHERE adminSetting.name=:name")
+@Entity
+public class AdminSettingEntity {
+  @Id
+  @Column(name = "id", nullable = false, insertable = true, updatable = false)
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = "admin_setting_id_generator")
+  private long id;
+
+  @Column(name = "name", nullable = false, insertable = true, updatable = false, unique = true)
+  @Basic
+  private String name;
+
+  @Column(name = "setting_type", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private String settingType;
+
+  @Column(name = "content", nullable = false, insertable = true, updatable = true)
+  @Lob
+  @Basic
+  private String content;
+
+  @Column(name = "updated_by", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private String updatedBy;
+
+  @Column(name = "update_timestamp", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private long updateTimestamp;
+
+  public AdminSettingEntity() {
+  }
+
+  public long getId() {
+    return id;
+  }
+
+  public void setId(long id) {
+    this.id = id;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getSettingType() {
+    return settingType;
+  }
+
+  public void setSettingType(String settingType) {
+    this.settingType = settingType;
+  }
+
+  public String getContent() {
+    return content;
+  }
+
+  public void setContent(String content) {
+    this.content = content;
+  }
+
+  public String getUpdatedBy() {
+    return updatedBy;
+  }
+
+  public void setUpdatedBy(String updatedBy) {
+    this.updatedBy = updatedBy;
+  }
+
+  public long getUpdateTimestamp() {
+    return updateTimestamp;
+  }
+
+  public void setUpdateTimestamp(long updateTimestamp) {
+    this.updateTimestamp = updateTimestamp;
+  }
+
+  public AdminSettingEntity clone() {
+    AdminSettingEntity cloned = new AdminSettingEntity();
+    cloned.setId(id);
+    cloned.setName(name);
+    cloned.setContent(content);
+    cloned.setSettingType(settingType);
+    cloned.setUpdatedBy(updatedBy);
+    cloned.setUpdateTimestamp(updateTimestamp);
+    return cloned;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    AdminSettingEntity entity = (AdminSettingEntity) o;
+    return id == entity.id &&
+            Objects.equals(name, entity.name) &&
+            Objects.equals(settingType, entity.settingType) &&
+            Objects.equals(content, entity.content) &&
+            Objects.equals(updatedBy, entity.updatedBy) &&
+            updateTimestamp == entity.updateTimestamp;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(id, name, settingType, content, updatedBy, updateTimestamp);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/META-INF/persistence.xml b/ambari-server/src/main/resources/META-INF/persistence.xml
index 3979bc0..280b9b6 100644
--- a/ambari-server/src/main/resources/META-INF/persistence.xml
+++ b/ambari-server/src/main/resources/META-INF/persistence.xml
@@ -88,9 +88,10 @@
     <class>org.apache.ambari.server.orm.entities.TopologyHostInfoEntity</class>
     <class>org.apache.ambari.server.orm.entities.TopologyHostTaskEntity</class>
     <class>org.apache.ambari.server.orm.entities.TopologyLogicalTaskEntity</class>
+    <class>org.apache.ambari.server.orm.entities.AdminSettingEntity</class>
     <class>org.apache.ambari.server.orm.entities.KerberosDescriptorEntity</class>
 
-    <properties>      
+    <properties>
       <property name="eclipselink.cache.size.default" value="10000" />
       <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
       <property name="eclipselink.jdbc.batch-writing.size" value="4000"/>

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java
new file mode 100644
index 0000000..b7e2145
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java
@@ -0,0 +1,213 @@
+/**
+ * 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.controller.internal;
+
+import com.google.common.collect.Lists;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.dao.AdminSettingDAO;
+import org.apache.ambari.server.orm.entities.AdminSettingEntity;
+import org.apache.commons.lang.RandomStringUtils;
+import org.easymock.Capture;
+import org.easymock.IMocksControl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_NAME_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_SETTING_TYPE_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_CONTENT_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_UPDATED_BY_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.createControl;
+
+import static org.junit.Assert.assertEquals;
+
+public class AdminSettingResourceProviderTest {
+  IMocksControl mockControl;
+  Request request;
+  AdminSettingDAO dao;
+  AdminSettingResourceProvider resourceProvider;
+
+  @Before
+  public void setUp() throws Exception {
+    mockControl = createControl();
+    request = mockControl.createMock(Request.class);
+    dao = mockControl.createMock(AdminSettingDAO.class);
+    resourceProvider = new AdminSettingResourceProvider();
+    setPrivateField(resourceProvider, "dao", dao);
+  }
+
+  @After
+  public void tearDown() {
+    mockControl.verify();
+    mockControl.reset();
+  }
+
+  @Test
+  public void testGetResources_instance() throws Exception {
+    String name = "motd";
+    AdminSettingEntity entity = newEntity(name);
+    Request request = PropertyHelper.getReadRequest(
+            ADMINSETTING_NAME_PROPERTY_ID,
+            ADMINSETTING_CONTENT_PROPERTY_ID,
+            ADMINSETTING_SETTING_TYPE_PROPERTY_ID,
+            ADMINSETTING_UPDATED_BY_PROPERTY_ID,
+            ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+
+    PredicateBuilder pb = new PredicateBuilder();
+    Predicate predicate = pb.begin().property(ADMINSETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+
+    expect(dao.findByName(name)).andReturn(entity).anyTimes();
+    mockControl.replay();
+    Set<Resource> response = resourceProvider.getResources(request, predicate);
+    assertEquals(1, response.size());
+    Resource resource = response.iterator().next();
+    assertEqualsEntityAndResource(entity, resource);
+  }
+
+  @Test
+  public void testGetResources_collection() throws Exception {
+    AdminSettingEntity entity1 = newEntity("motd");
+    AdminSettingEntity entity2 = newEntity("ldap");
+    Request request = PropertyHelper.getReadRequest(
+            ADMINSETTING_NAME_PROPERTY_ID,
+            ADMINSETTING_CONTENT_PROPERTY_ID,
+            ADMINSETTING_SETTING_TYPE_PROPERTY_ID,
+            ADMINSETTING_UPDATED_BY_PROPERTY_ID,
+            ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+
+    expect(dao.findAll()).andReturn(Lists.newArrayList(entity1, entity2));
+    mockControl.replay();
+    Set<Resource> response = resourceProvider.getResources(request, null);
+    assertEquals(2, response.size());
+
+    Map<Object, Resource> resourceMap = new HashMap<>();
+    Iterator<Resource> resourceIterator = response.iterator();
+    Resource nextResource = resourceIterator.next();
+    resourceMap.put(nextResource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID), nextResource);
+    nextResource = resourceIterator.next();
+    resourceMap.put(nextResource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID), nextResource);
+
+    assertEqualsEntityAndResource(entity1, resourceMap.get(entity1.getName()));
+    assertEqualsEntityAndResource(entity2, resourceMap.get(entity2.getName()));
+  }
+
+  @Test
+  public void testCreateResource() throws Exception {
+    AdminSettingEntity entity = newEntity("motd");
+    Map<String, Object> properties = new HashMap<>();
+    properties.put(ADMINSETTING_NAME_PROPERTY_ID, entity.getName());
+    properties.put(ADMINSETTING_CONTENT_PROPERTY_ID, entity.getContent());
+    properties.put(ADMINSETTING_UPDATED_BY_PROPERTY_ID, entity.getUpdatedBy());
+    properties.put(ADMINSETTING_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
+    Capture<AdminSettingEntity> entityCapture = Capture.newInstance();
+    Request request = PropertyHelper.getCreateRequest(Collections.singleton(properties), null);
+
+    dao.create(capture(entityCapture));
+    mockControl.replay();
+
+    RequestStatus response = resourceProvider.createResources(request);
+    AdminSettingEntity capturedEntity = entityCapture.getValue();
+    assertEquals(RequestStatus.Status.Complete, response.getStatus());
+    Set<Resource> associatedResources = response.getAssociatedResources();
+    assertEquals(1, associatedResources.size());
+    assertEquals(entity.getName(), capturedEntity.getName());
+    assertEquals(entity.getContent(), capturedEntity.getContent());
+    assertEquals(entity.getSettingType(), capturedEntity.getSettingType());
+    assertEquals(entity.getUpdatedBy(), capturedEntity.getUpdatedBy());
+  }
+
+  @Test
+  public void testUpdateResources() throws Exception {
+    String name = "motd";
+    AdminSettingEntity oldEntity = newEntity(name);
+    AdminSettingEntity updatedEntity = oldEntity.clone();
+    updatedEntity.setContent("{text}");
+    updatedEntity.setSettingType("new-type");
+    Map<String, Object> properties = new HashMap<>();
+    properties.put(ADMINSETTING_NAME_PROPERTY_ID, name);
+    properties.put(ADMINSETTING_CONTENT_PROPERTY_ID, updatedEntity.getContent());
+    properties.put(ADMINSETTING_SETTING_TYPE_PROPERTY_ID, updatedEntity.getSettingType());
+    Request request = PropertyHelper.getUpdateRequest(properties, null);
+    PredicateBuilder pb = new PredicateBuilder();
+    Predicate predicate = pb.begin().property(ADMINSETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+    Capture<AdminSettingEntity> capture = Capture.newInstance();
+
+    expect(dao.findByName(name)).andReturn(oldEntity);
+    expect(dao.merge(capture(capture))).andReturn(updatedEntity);
+    mockControl.replay();
+
+    RequestStatus response = resourceProvider.updateResources(request, predicate);
+    AdminSettingEntity capturedEntity = capture.getValue();
+    assertEquals(RequestStatus.Status.Complete, response.getStatus());
+    assertEquals(updatedEntity.getId(), capturedEntity.getId());
+    assertEquals(updatedEntity.getName(), capturedEntity.getName());
+    assertEquals(updatedEntity.getSettingType(), capturedEntity.getSettingType());
+    assertEquals(updatedEntity.getContent(), capturedEntity.getContent());
+    assertEquals(updatedEntity.getUpdatedBy(), capturedEntity.getUpdatedBy());
+  }
+
+  @Test
+  public void testDeleteResources() throws Exception {
+    String name = "motd";
+    PredicateBuilder pb = new PredicateBuilder();
+    Predicate predicate = pb.begin().property(ADMINSETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+    dao.removeByName(name);
+    mockControl.replay();
+    resourceProvider.deleteResources(predicate);
+  }
+
+  private AdminSettingEntity newEntity(String name) {
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setName(name);
+    entity.setContent(RandomStringUtils.randomAlphabetic(10));
+    entity.setSettingType(RandomStringUtils.randomAlphabetic(5));
+    entity.setUpdatedBy("ambari");
+    entity.setUpdateTimestamp(System.currentTimeMillis());
+    return entity;
+  }
+
+  private void assertEqualsEntityAndResource(AdminSettingEntity entity, Resource resource) {
+    assertEquals(entity.getName(), resource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID));
+    assertEquals(entity.getSettingType(), resource.getPropertyValue(ADMINSETTING_SETTING_TYPE_PROPERTY_ID));
+    assertEquals(entity.getContent(), resource.getPropertyValue(ADMINSETTING_CONTENT_PROPERTY_ID));
+    assertEquals(entity.getUpdatedBy(), resource.getPropertyValue(ADMINSETTING_UPDATED_BY_PROPERTY_ID));
+    assertEquals(entity.getUpdateTimestamp(), resource.getPropertyValue(ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID));
+  }
+
+  private void setPrivateField(Object o, String field, Object value) throws Exception{
+    Class<?> c = o.getClass();
+    Field f = c.getDeclaredField(field);
+    f.setAccessible(true);
+    f.set(o, value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java
new file mode 100644
index 0000000..eabbb77
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.entities.AdminSettingEntity;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import static junit.framework.Assert.assertEquals;
+
+public class AdminSettingDAOTest {
+  private  Injector injector;
+  private  AdminSettingDAO dao;
+
+  @Before
+  public void setUp() {
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    dao = injector.getInstance(AdminSettingDAO.class);
+    injector.getInstance(GuiceJpaInitializer.class);
+    injector.getInstance(OrmTestHelper.class).createCluster();
+  }
+
+  @Test
+  public void testCRUD() {
+    Map<String, AdminSettingEntity> entities = new HashMap<>();
+    //Create
+    for (int i=0; i < 3; i++) {
+      AdminSettingEntity entity = new AdminSettingEntity();
+      entity.setName("motd" + i);
+      entity.setContent("test content" + i);
+      entity.setUpdatedBy("ambari");
+      entity.setSettingType("ambari-server");
+      entity.setUpdateTimestamp(System.currentTimeMillis());
+      entities.put(entity.getName(), entity);
+      dao.create(entity);
+    }
+
+    //Retrieve
+    retrieveAndValidateSame(entities);
+    assertEquals(entities.size(), dao.findAll().size());
+
+
+    //Update
+    for(Map.Entry<String, AdminSettingEntity> entry : entities.entrySet()) {
+      entry.getValue().setContent(Objects.toString(Math.random()));
+      dao.merge(entry.getValue());
+    }
+
+    retrieveAndValidateSame(entities);
+    assertEquals(entities.size(), dao.findAll().size());
+
+    //Delete
+    for(Map.Entry<String, AdminSettingEntity> entry : entities.entrySet()) {
+      dao.removeByName(entry.getKey());
+    }
+    assertEquals(0, dao.findAll().size());
+  }
+
+  private void retrieveAndValidateSame(Map<String, AdminSettingEntity> entities) {
+    for(Map.Entry<String, AdminSettingEntity> entry : entities.entrySet()) {
+      String name = entry.getKey();
+      assertEquals(entry.getValue(), dao.findByName(name));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/f2a44a7e/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java
new file mode 100644
index 0000000..a7cba23
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java
@@ -0,0 +1,91 @@
+/**
+ * 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 org.junit.Assert;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * AdminSettingEntity unit tests.
+ */
+public class AdminSettingEntityTest {
+
+  @Test
+  public void testSetGetId() {
+    long id = 1000;
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setId(id);
+    assertEquals(id, entity.getId());
+  }
+
+  @Test
+  public void testSetGetName() {
+    String name = "motd";
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setName(name);
+    assertEquals(name, entity.getName());
+  }
+
+  @Test
+  public void testSetGetSettingType() {
+    String settingType = "ambari-server";
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setSettingType(settingType);
+    assertEquals(settingType, entity.getSettingType());
+  }
+
+  @Test
+  public void testSetGetContent() {
+    String content = "{tag:random-tag, text:random-text}";
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setContent(content);
+    assertEquals(content, entity.getContent());
+  }
+
+  @Test
+  public void testSetGetUpdatedBy() {
+    String updatedBy = "ambari";
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setUpdatedBy(updatedBy);
+    assertEquals(updatedBy, entity.getUpdatedBy());
+  }
+
+  @Test
+  public void testSetGetUpdatedTimeStamp() {
+    long updateTimeStamp = 1234567890;
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setUpdateTimestamp(updateTimeStamp);
+    assertEquals(updateTimeStamp, entity.getUpdateTimestamp());
+  }
+
+  @Test
+  public void testEquals() {
+    AdminSettingEntity entity = new AdminSettingEntity();
+    entity.setId(1);
+    entity.setName("motd");
+    entity.setContent("{tag:random-tag, text:random-text}");
+    entity.setSettingType("ambari-server");
+    entity.setUpdatedBy("ambari");
+    entity.setUpdateTimestamp(1234567890);
+    AdminSettingEntity newEntity = entity.clone();
+    assertEquals(entity, newEntity);
+  }
+
+}


Mime
View raw message