You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2016/02/02 03:17:25 UTC
[1/2] ambari git commit: AMBARI-14869: Rename AdminSetting API to
Setting (Ajit Kumar via smnaha)
Repository: ambari
Updated Branches:
refs/heads/trunk 6ce156554 -> 774d689ee
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java
new file mode 100644
index 0000000..598e420
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.api.services;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.parsers.RequestBodyParser;
+import org.apache.ambari.server.api.services.serializers.ResultSerializer;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit test for {@link SettingService}
+ */
+public class SettingServiceTest extends BaseServiceTest {
+ @Override
+ public List<ServiceTestInvocation> getTestInvocations() throws Exception {
+ List<ServiceTestInvocation> listInvocations = new ArrayList<>();
+
+ //getSetting
+ SettingService settingService = new TestSettingService("settingName");
+ Method m = settingService.getClass().getMethod("getSetting", String.class, HttpHeaders.class, UriInfo.class, String.class);
+ Object[] args = new Object[] {null, getHttpHeaders(), getUriInfo(), "settingName"};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.GET, settingService, m, args, null));
+
+ //getSettings
+ settingService = new TestSettingService(null);
+ m = settingService.getClass().getMethod("getSettings", String.class, HttpHeaders.class, UriInfo.class);
+ args = new Object[] {null, getHttpHeaders(), getUriInfo()};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.GET, settingService, m, args, null));
+
+ //createSetting
+ settingService = new TestSettingService(null);
+ m = settingService.getClass().getMethod("createSetting", String.class, HttpHeaders.class, UriInfo.class);
+ args = new Object[] {"body", getHttpHeaders(), getUriInfo()};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.POST, settingService, m, args, "body"));
+
+ //updateSetting
+ settingService = new TestSettingService("settingName");
+ m = settingService.getClass().getMethod("updateSetting", String.class, HttpHeaders.class, UriInfo.class, String.class);
+ args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "settingName"};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.PUT, settingService, m, args, "body"));
+
+ //deleteSetting
+ settingService = new TestSettingService("settingName");
+ m = settingService.getClass().getMethod("deleteSetting", HttpHeaders.class, UriInfo.class, String.class);
+ args = new Object[] {getHttpHeaders(), getUriInfo(), "settingName"};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, settingService, m, args, null));
+
+ return listInvocations;
+ }
+
+ private class TestSettingService extends SettingService {
+ private String settingName;
+
+ private TestSettingService(String settingName) {
+ this.settingName = settingName;
+ }
+
+ @Override
+ ResourceInstance createSettingResource(String settingName) {
+ assertEquals(this.settingName, settingName);
+ return getTestResource();
+ }
+
+ @Override
+ RequestFactory getRequestFactory() {
+ return getTestRequestFactory();
+ }
+
+ @Override
+ protected RequestBodyParser getBodyParser() {
+ return getTestBodyParser();
+ }
+
+ @Override
+ protected ResultSerializer getResultSerializer() {
+ return getTestResultSerializer();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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
deleted file mode 100644
index e95449c..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java
+++ /dev/null
@@ -1,356 +0,0 @@
-/**
- * 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.DuplicateResourceException;
-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.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.ambari.server.security.TestAuthenticationFactory;
-import org.apache.ambari.server.security.authorization.AuthorizationException;
-import org.apache.ambari.server.security.authorization.AuthorizationHelper;
-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 org.springframework.security.core.context.SecurityContextHolder;
-
-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;
- AdminSettingDAO dao;
- AdminSettingResourceProvider resourceProvider;
-
-
- @Before
- public void setUp() throws Exception {
- mockControl = createControl();
- dao = mockControl.createMock(AdminSettingDAO.class);
- resourceProvider = new AdminSettingResourceProvider();
- setPrivateField(resourceProvider, "dao", dao);
- }
-
- @After
- public void tearDown() {
- mockControl.verify();
- SecurityContextHolder.getContext().setAuthentication(null);
- mockControl.reset();
- }
-
- @Test(expected = AuthorizationException.class)
- public void testGetResources_instance_noAuth() throws Exception {
- getResources_instance(newEntity("motd"), readRequest());
- }
-
- @Test
- public void testGetResources_instance_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- String name = "motd";
- AdminSettingEntity entity = newEntity(name);
-
- Set<Resource> response = getResources_instance(entity, readRequest());
- assertEquals(1, response.size());
- Resource resource = response.iterator().next();
- assertEqualsEntityAndResource(entity, resource);
- }
-
- @Test
- public void testGetResources_instance_admin() throws Exception {
- setupAuthenticationForAdmin();
- AdminSettingEntity entity = newEntity("motd");
- Set<Resource> response = getResources_instance(entity, readRequest());
- assertEquals(1, response.size());
- Resource resource = response.iterator().next();
- assertEqualsEntityAndResource(entity, resource);
- }
-
- @Test(expected = AuthorizationException.class)
- public void testGetResources_collection_noAuth() throws Exception {
- mockControl.replay();
- 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);
- resourceProvider.getResources(request, null);
- }
-
- @Test
- public void testGetResources_collection_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
-
- 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 testGetResources_collection_admin() throws Exception {
- setupAuthenticationForAdmin();
-
- 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(expected = AuthorizationException.class)
- public void testCreateResource_noAuth() throws Exception {
- mockControl.replay();
- resourceProvider.createResources(createRequest(newEntity("moted")));
- }
-
- @Test(expected = AuthorizationException.class)
- public void testCreateResource_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- mockControl.replay();
- resourceProvider.createResources(createRequest(newEntity("motd")));
- }
-
- @Test
- public void testCreateResource_admin() throws Exception {
- setupAuthenticationForAdmin();
- AdminSettingEntity entity = newEntity("motd");
- Capture<AdminSettingEntity> entityCapture = Capture.newInstance();
- Request request = createRequest(entity);
-
- expect(dao.findByName(entity.getName())).andReturn(null);
- dao.create(capture(entityCapture));
- mockControl.replay();
-
- RequestStatus response = resourceProvider.createResources(request);
- assertEquals(RequestStatus.Status.Complete, response.getStatus());
- Set<Resource> associatedResources = response.getAssociatedResources();
- assertEquals(1, associatedResources.size());
- AdminSettingEntity capturedEntity = entityCapture.getValue();
- assertEquals(entity.getName(), capturedEntity.getName());
- assertEquals(entity.getContent(), capturedEntity.getContent());
- assertEquals(entity.getSettingType(), capturedEntity.getSettingType());
- assertEquals(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
- }
-
- @Test(expected = ResourceAlreadyExistsException.class)
- public void testCreateDuplicateResource() throws Exception {
- setupAuthenticationForAdmin();
- AdminSettingEntity entity = newEntity("motd");
- Request request = createRequest(entity);
-
- expect(dao.findByName(entity.getName())).andReturn(entity);
- mockControl.replay();
- resourceProvider.createResources(request);
- }
-
- @Test(expected = AuthorizationException.class)
- public void testUpdateResources_noAuth() throws Exception {
- mockControl.replay();
- resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
- }
-
- @Test(expected = AuthorizationException.class)
- public void testUpdateResources_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- mockControl.replay();
- resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
- }
-
- @Test
- public void testUpdateResources_admin() throws Exception {
- setupAuthenticationForAdmin();
- String name = "motd";
- AdminSettingEntity oldEntity = newEntity(name);
- AdminSettingEntity updatedEntity = oldEntity.clone();
- updatedEntity.setContent("{text}");
- updatedEntity.setSettingType("new-type");
-
- 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(updateRequest(updatedEntity), 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(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
- }
-
- @Test(expected = AuthorizationException.class)
- public void testDeleteResources_noAuth() throws Exception {
- mockControl.replay();
- resourceProvider.deleteResources(null);
- }
-
-
- @Test(expected = AuthorizationException.class)
- public void testDeleteResources_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- mockControl.replay();
- resourceProvider.deleteResources(null);
- }
-
- @Test
- public void testDeleteResources() throws Exception {
- setupAuthenticationForAdmin();
-
- 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 Set<Resource> getResources_instance(AdminSettingEntity entity, Request request) throws Exception {
- String name = entity.getName();
- 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();
- return resourceProvider.getResources(request, predicate);
- }
-
-
- private Request readRequest() {
- return 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);
- }
-
- private Request createRequest(AdminSettingEntity entity) {
- 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());
- return PropertyHelper.getCreateRequest(Collections.singleton(properties), null);
- }
-
- private Request updateRequest(AdminSettingEntity entity) {
- 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_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
- return PropertyHelper.getUpdateRequest(properties, null);
- }
-
- private void setupAuthenticationForClusterUser() {
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createClusterUser());
- }
-
- private void setupAuthenticationForAdmin() {
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
- }
-
- 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/774d689e/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java
new file mode 100644
index 0000000..c133220
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java
@@ -0,0 +1,355 @@
+/**
+ * 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.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.dao.SettingDAO;
+import org.apache.ambari.server.orm.entities.SettingEntity;
+import org.apache.ambari.server.security.TestAuthenticationFactory;
+import org.apache.ambari.server.security.authorization.AuthorizationException;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+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 org.springframework.security.core.context.SecurityContextHolder;
+
+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.SettingResourceProvider.SETTING_NAME_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_SETTING_TYPE_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_CONTENT_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_UPDATED_BY_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_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 SettingResourceProviderTest {
+ IMocksControl mockControl;
+ SettingDAO dao;
+ SettingResourceProvider resourceProvider;
+
+
+ @Before
+ public void setUp() throws Exception {
+ mockControl = createControl();
+ dao = mockControl.createMock(SettingDAO.class);
+ resourceProvider = new SettingResourceProvider();
+ setPrivateField(resourceProvider, "dao", dao);
+ }
+
+ @After
+ public void tearDown() {
+ mockControl.verify();
+ SecurityContextHolder.getContext().setAuthentication(null);
+ mockControl.reset();
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testGetResources_instance_noAuth() throws Exception {
+ getResources_instance(newEntity("motd"), readRequest());
+ }
+
+ @Test
+ public void testGetResources_instance_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ String name = "motd";
+ SettingEntity entity = newEntity(name);
+
+ Set<Resource> response = getResources_instance(entity, readRequest());
+ assertEquals(1, response.size());
+ Resource resource = response.iterator().next();
+ assertEqualsEntityAndResource(entity, resource);
+ }
+
+ @Test
+ public void testGetResources_instance_admin() throws Exception {
+ setupAuthenticationForAdmin();
+ SettingEntity entity = newEntity("motd");
+ Set<Resource> response = getResources_instance(entity, readRequest());
+ assertEquals(1, response.size());
+ Resource resource = response.iterator().next();
+ assertEqualsEntityAndResource(entity, resource);
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testGetResources_collection_noAuth() throws Exception {
+ mockControl.replay();
+ Request request = PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+ resourceProvider.getResources(request, null);
+ }
+
+ @Test
+ public void testGetResources_collection_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+
+ SettingEntity entity1 = newEntity("motd");
+ SettingEntity entity2 = newEntity("ldap");
+ Request request = PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_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(SETTING_NAME_PROPERTY_ID), nextResource);
+ nextResource = resourceIterator.next();
+ resourceMap.put(nextResource.getPropertyValue(SETTING_NAME_PROPERTY_ID), nextResource);
+ assertEqualsEntityAndResource(entity1, resourceMap.get(entity1.getName()));
+ assertEqualsEntityAndResource(entity2, resourceMap.get(entity2.getName()));
+ }
+
+ @Test
+ public void testGetResources_collection_admin() throws Exception {
+ setupAuthenticationForAdmin();
+
+ SettingEntity entity1 = newEntity("motd");
+ SettingEntity entity2 = newEntity("ldap");
+ Request request = PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_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(SETTING_NAME_PROPERTY_ID), nextResource);
+ nextResource = resourceIterator.next();
+ resourceMap.put(nextResource.getPropertyValue(SETTING_NAME_PROPERTY_ID), nextResource);
+ assertEqualsEntityAndResource(entity1, resourceMap.get(entity1.getName()));
+ assertEqualsEntityAndResource(entity2, resourceMap.get(entity2.getName()));
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testCreateResource_noAuth() throws Exception {
+ mockControl.replay();
+ resourceProvider.createResources(createRequest(newEntity("moted")));
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testCreateResource_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ mockControl.replay();
+ resourceProvider.createResources(createRequest(newEntity("motd")));
+ }
+
+ @Test
+ public void testCreateResource_admin() throws Exception {
+ setupAuthenticationForAdmin();
+ SettingEntity entity = newEntity("motd");
+ Capture<SettingEntity> entityCapture = Capture.newInstance();
+ Request request = createRequest(entity);
+
+ expect(dao.findByName(entity.getName())).andReturn(null);
+ dao.create(capture(entityCapture));
+ mockControl.replay();
+
+ RequestStatus response = resourceProvider.createResources(request);
+ assertEquals(RequestStatus.Status.Complete, response.getStatus());
+ Set<Resource> associatedResources = response.getAssociatedResources();
+ assertEquals(1, associatedResources.size());
+ SettingEntity capturedEntity = entityCapture.getValue();
+ assertEquals(entity.getName(), capturedEntity.getName());
+ assertEquals(entity.getContent(), capturedEntity.getContent());
+ assertEquals(entity.getSettingType(), capturedEntity.getSettingType());
+ assertEquals(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
+ }
+
+ @Test(expected = ResourceAlreadyExistsException.class)
+ public void testCreateDuplicateResource() throws Exception {
+ setupAuthenticationForAdmin();
+ SettingEntity entity = newEntity("motd");
+ Request request = createRequest(entity);
+
+ expect(dao.findByName(entity.getName())).andReturn(entity);
+ mockControl.replay();
+ resourceProvider.createResources(request);
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testUpdateResources_noAuth() throws Exception {
+ mockControl.replay();
+ resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testUpdateResources_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ mockControl.replay();
+ resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
+ }
+
+ @Test
+ public void testUpdateResources_admin() throws Exception {
+ setupAuthenticationForAdmin();
+ String name = "motd";
+ SettingEntity oldEntity = newEntity(name);
+ SettingEntity updatedEntity = oldEntity.clone();
+ updatedEntity.setContent("{text}");
+ updatedEntity.setSettingType("new-type");
+
+ PredicateBuilder pb = new PredicateBuilder();
+ Predicate predicate = pb.begin().property(SETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+ Capture<SettingEntity> capture = Capture.newInstance();
+
+ expect(dao.findByName(name)).andReturn(oldEntity);
+ expect(dao.merge(capture(capture))).andReturn(updatedEntity);
+ mockControl.replay();
+
+ RequestStatus response = resourceProvider.updateResources(updateRequest(updatedEntity), predicate);
+ SettingEntity 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(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testDeleteResources_noAuth() throws Exception {
+ mockControl.replay();
+ resourceProvider.deleteResources(null);
+ }
+
+
+ @Test(expected = AuthorizationException.class)
+ public void testDeleteResources_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ mockControl.replay();
+ resourceProvider.deleteResources(null);
+ }
+
+ @Test
+ public void testDeleteResources() throws Exception {
+ setupAuthenticationForAdmin();
+
+ String name = "motd";
+ PredicateBuilder pb = new PredicateBuilder();
+ Predicate predicate = pb.begin().property(SETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+ dao.removeByName(name);
+ mockControl.replay();
+ resourceProvider.deleteResources(predicate);
+ }
+
+ private Set<Resource> getResources_instance(SettingEntity entity, Request request) throws Exception {
+ String name = entity.getName();
+ PredicateBuilder pb = new PredicateBuilder();
+ Predicate predicate = pb.begin().property(SETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+
+ expect(dao.findByName(name)).andReturn(entity).anyTimes();
+ mockControl.replay();
+ return resourceProvider.getResources(request, predicate);
+ }
+
+
+ private Request readRequest() {
+ return PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+ }
+
+ private Request createRequest(SettingEntity entity) {
+ Map<String, Object> properties = new HashMap<>();
+ properties.put(SETTING_NAME_PROPERTY_ID, entity.getName());
+ properties.put(SETTING_CONTENT_PROPERTY_ID, entity.getContent());
+ properties.put(SETTING_UPDATED_BY_PROPERTY_ID, entity.getUpdatedBy());
+ properties.put(SETTING_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
+ return PropertyHelper.getCreateRequest(Collections.singleton(properties), null);
+ }
+
+ private Request updateRequest(SettingEntity entity) {
+ Map<String, Object> properties = new HashMap<>();
+ properties.put(SETTING_NAME_PROPERTY_ID, entity.getName());
+ properties.put(SETTING_CONTENT_PROPERTY_ID, entity.getContent());
+ properties.put(SETTING_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
+ return PropertyHelper.getUpdateRequest(properties, null);
+ }
+
+ private void setupAuthenticationForClusterUser() {
+ SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createClusterUser());
+ }
+
+ private void setupAuthenticationForAdmin() {
+ SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
+ }
+
+ private SettingEntity newEntity(String name) {
+ SettingEntity entity = new SettingEntity();
+ 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(SettingEntity entity, Resource resource) {
+ assertEquals(entity.getName(), resource.getPropertyValue(SETTING_NAME_PROPERTY_ID));
+ assertEquals(entity.getSettingType(), resource.getPropertyValue(SETTING_SETTING_TYPE_PROPERTY_ID));
+ assertEquals(entity.getContent(), resource.getPropertyValue(SETTING_CONTENT_PROPERTY_ID));
+ assertEquals(entity.getUpdatedBy(), resource.getPropertyValue(SETTING_UPDATED_BY_PROPERTY_ID));
+ assertEquals(entity.getUpdateTimestamp(), resource.getPropertyValue(SETTING_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/774d689e/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
deleted file mode 100644
index 8258974..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * 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;
-import static junit.framework.Assert.assertNull;
-
-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());
-
- //Should return null if doesn't exist.
- assertNull(dao.findByName("does-not-exist"));
-
-
- //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/774d689e/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java
new file mode 100644
index 0000000..77f87be
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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.SettingEntity;
+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;
+import static junit.framework.Assert.assertNull;
+
+public class SettingDAOTest {
+ private Injector injector;
+ private SettingDAO dao;
+
+ @Before
+ public void setUp() {
+ injector = Guice.createInjector(new InMemoryDefaultTestModule());
+ dao = injector.getInstance(SettingDAO.class);
+ injector.getInstance(GuiceJpaInitializer.class);
+ injector.getInstance(OrmTestHelper.class).createCluster();
+ }
+
+ @Test
+ public void testCRUD() {
+ Map<String, SettingEntity> entities = new HashMap<>();
+ //Create
+ for (int i=0; i < 3; i++) {
+ SettingEntity entity = new SettingEntity();
+ 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());
+
+ //Should return null if doesn't exist.
+ assertNull(dao.findByName("does-not-exist"));
+
+
+ //Update
+ for(Map.Entry<String, SettingEntity> 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, SettingEntity> entry : entities.entrySet()) {
+ dao.removeByName(entry.getKey());
+ }
+ assertEquals(0, dao.findAll().size());
+ }
+
+ private void retrieveAndValidateSame(Map<String, SettingEntity> entities) {
+ for(Map.Entry<String, SettingEntity> entry : entities.entrySet()) {
+ String name = entry.getKey();
+ assertEquals(entry.getValue(), dao.findByName(name));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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
deleted file mode 100644
index a7cba23..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java
new file mode 100644
index 0000000..defe948
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * SettingEntity unit tests.
+ */
+public class SettingEntityTest {
+
+ @Test
+ public void testSetGetId() {
+ long id = 1000;
+ SettingEntity entity = new SettingEntity();
+ entity.setId(id);
+ assertEquals(id, entity.getId());
+ }
+
+ @Test
+ public void testSetGetName() {
+ String name = "motd";
+ SettingEntity entity = new SettingEntity();
+ entity.setName(name);
+ assertEquals(name, entity.getName());
+ }
+
+ @Test
+ public void testSetGetSettingType() {
+ String settingType = "ambari-server";
+ SettingEntity entity = new SettingEntity();
+ entity.setSettingType(settingType);
+ assertEquals(settingType, entity.getSettingType());
+ }
+
+ @Test
+ public void testSetGetContent() {
+ String content = "{tag:random-tag, text:random-text}";
+ SettingEntity entity = new SettingEntity();
+ entity.setContent(content);
+ assertEquals(content, entity.getContent());
+ }
+
+ @Test
+ public void testSetGetUpdatedBy() {
+ String updatedBy = "ambari";
+ SettingEntity entity = new SettingEntity();
+ entity.setUpdatedBy(updatedBy);
+ assertEquals(updatedBy, entity.getUpdatedBy());
+ }
+
+ @Test
+ public void testSetGetUpdatedTimeStamp() {
+ long updateTimeStamp = 1234567890;
+ SettingEntity entity = new SettingEntity();
+ entity.setUpdateTimestamp(updateTimeStamp);
+ assertEquals(updateTimeStamp, entity.getUpdateTimestamp());
+ }
+
+ @Test
+ public void testEquals() {
+ SettingEntity entity = new SettingEntity();
+ entity.setId(1);
+ entity.setName("motd");
+ entity.setContent("{tag:random-tag, text:random-text}");
+ entity.setSettingType("ambari-server");
+ entity.setUpdatedBy("ambari");
+ entity.setUpdateTimestamp(1234567890);
+ SettingEntity newEntity = entity.clone();
+ assertEquals(entity, newEntity);
+ }
+
+}
[2/2] ambari git commit: AMBARI-14869: Rename AdminSetting API to
Setting (Ajit Kumar via smnaha)
Posted by sm...@apache.org.
AMBARI-14869: Rename AdminSetting API to Setting (Ajit Kumar via smnaha)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/774d689e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/774d689e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/774d689e
Branch: refs/heads/trunk
Commit: 774d689eee8a26a0511e23f182a1d3e65c22c5eb
Parents: 6ce1565
Author: Nahappan Somasundaram <ns...@hortonworks.com>
Authored: Mon Feb 1 18:15:03 2016 -0800
Committer: Nahappan Somasundaram <ns...@hortonworks.com>
Committed: Mon Feb 1 18:15:03 2016 -0800
----------------------------------------------------------------------
.../resources/ResourceInstanceFactoryImpl.java | 4 +-
.../api/services/AdminSettingService.java | 148 --------
.../server/api/services/SettingService.java | 148 ++++++++
.../internal/AdminSettingResourceProvider.java | 250 -------------
.../internal/DefaultProviderModule.java | 4 +-
.../internal/SettingResourceProvider.java | 251 +++++++++++++
.../ambari/server/controller/spi/Resource.java | 4 +-
.../ambari/server/orm/dao/AdminSettingDAO.java | 100 ------
.../ambari/server/orm/dao/SettingDAO.java | 100 ++++++
.../server/orm/entities/AdminSettingEntity.java | 149 --------
.../server/orm/entities/SettingEntity.java | 149 ++++++++
.../authorization/RoleAuthorization.java | 2 +-
.../main/resources/Ambari-DDL-Derby-CREATE.sql | 8 +-
.../main/resources/Ambari-DDL-MySQL-CREATE.sql | 8 +-
.../main/resources/Ambari-DDL-Oracle-CREATE.sql | 8 +-
.../resources/Ambari-DDL-Postgres-CREATE.sql | 8 +-
.../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql | 10 +-
.../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 8 +-
.../resources/Ambari-DDL-SQLServer-CREATE.sql | 8 +-
.../src/main/resources/META-INF/persistence.xml | 2 +-
.../api/services/AdminSettingServiceTest.java | 101 ------
.../server/api/services/SettingServiceTest.java | 101 ++++++
.../AdminSettingResourceProviderTest.java | 356 -------------------
.../internal/SettingResourceProviderTest.java | 355 ++++++++++++++++++
.../server/orm/dao/AdminSettingDAOTest.java | 93 -----
.../ambari/server/orm/dao/SettingDAOTest.java | 93 +++++
.../orm/entities/AdminSettingEntityTest.java | 91 -----
.../server/orm/entities/SettingEntityTest.java | 90 +++++
28 files changed, 1324 insertions(+), 1325 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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 070a505..4c12094 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,8 +408,8 @@ 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");
+ case Setting:
+ resourceDefinition = new SimpleResourceDefinition(Resource.Type.Setting, "setting", "settings");
break;
default:
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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
deleted file mode 100644
index 2c5b77d..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AdminSettingService.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * 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/774d689e/ambari-server/src/main/java/org/apache/ambari/server/api/services/SettingService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/SettingService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/SettingService.java
new file mode 100644
index 0000000..db6f002
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/SettingService.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 setting resource requests.
+ */
+@Path("/settings/")
+public class SettingService extends BaseService {
+
+ /**
+ * Construct a SettingService.
+ */
+ public SettingService() {
+
+ }
+
+ /**
+ * Handles: GET /settings
+ * Get all clusters.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ *
+ * @return 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 /settings/{settingName}
+ * Get a specific setting.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @param settingName settingName
+ *
+ * @return 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 /settings/{settingName}
+ * Create a specific 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 /settings/{settingName}
+ * Update a specific 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 /settings/{settingName}
+ * Delete a specific 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 a setting resource instance.
+ *
+ * @param settingName setting name
+ *
+ * @return a setting resource instance
+ */
+ ResourceInstance createSettingResource(String settingName) {
+ return createResource(Resource.Type.Setting,
+ Collections.singletonMap(Resource.Type.Setting, settingName));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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
deleted file mode 100644
index e8d5b5e..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProvider.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/**
- * 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.DuplicateResourceException;
-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.ambari.server.security.authorization.AuthorizationHelper;
-import org.apache.ambari.server.security.authorization.RoleAuthorization;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-
-import java.util.EnumSet;
-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);
- EnumSet<RoleAuthorization> requiredAuthorizations = EnumSet.of(RoleAuthorization.AMBARI_MANAGE_ADMIN_SETTINGS);
- setRequiredCreateAuthorizations(requiredAuthorizations);
- setRequiredDeleteAuthorizations(requiredAuthorizations);
- setRequiredUpdateAuthorizations(requiredAuthorizations);
- }
-
- @Override
- protected Set<String> getPKPropertyIds() {
- return new HashSet<>(keyPropertyIds.values());
- }
-
- @Override
- public RequestStatus createResourcesAuthorized(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> getResourcesAuthorized(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 updateResourcesAuthorized(Request request, Predicate predicate)
- throws NoSuchResourceException, NoSuchParentResourceException, SystemException {
- modifyResources(newUpdateCommand(request));
- return getRequestStatus(null);
- }
-
- @Override
- public RequestStatus deleteResourcesAuthorized(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);
- if (dao.findByName(entity.getName()) != null) {
- throw new DuplicateResourceException(
- String.format("Setting already exists. setting name :%s ", entity.getName()));
- }
- 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());
- }
-
- entity.setUpdatedBy(AuthorizationHelper.getAuthenticatedName());
- 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(AuthorizationHelper.getAuthenticatedName());
- entity.setUpdateTimestamp(System.currentTimeMillis());
- return entity;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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 ab76458..da334b2 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
@@ -112,8 +112,8 @@ public class DefaultProviderModule extends AbstractProviderModule {
return new OperatingSystemResourceProvider(managementController);
case Repository:
return new RepositoryResourceProvider(managementController);
- case AdminSetting:
- return new AdminSettingResourceProvider();
+ case Setting:
+ return new SettingResourceProvider();
case Artifact:
return new ArtifactResourceProvider(managementController);
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SettingResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SettingResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SettingResourceProvider.java
new file mode 100644
index 0000000..e1f9015
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/SettingResourceProvider.java
@@ -0,0 +1,251 @@
+/**
+ * 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.DuplicateResourceException;
+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.SettingDAO;
+import org.apache.ambari.server.orm.entities.SettingEntity;
+import org.apache.ambari.server.security.authorization.AuthorizationException;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+import org.apache.ambari.server.security.authorization.RoleAuthorization;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.EnumSet;
+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 SettingEntity}.
+ */
+@StaticallyInject
+public class SettingResourceProvider extends AbstractAuthorizedResourceProvider {
+
+ private static final String SETTINGS = "Settings";
+ protected static final String ID = "id";
+ protected static final String SETTING = "Setting";
+ protected static final String SETTING_NAME_PROPERTY_ID = PropertyHelper.getPropertyId(SETTINGS, "name");
+ protected static final String SETTING_SETTING_TYPE_PROPERTY_ID = PropertyHelper.getPropertyId(SETTINGS, "setting_type");
+ protected static final String SETTING_CONTENT_PROPERTY_ID = PropertyHelper.getPropertyId(SETTINGS, "content");
+ protected static final String SETTING_UPDATED_BY_PROPERTY_ID = PropertyHelper.getPropertyId(SETTINGS, "updated_by");
+ protected static final String SETTING_UPDATE_TIMESTAMP_PROPERTY_ID = PropertyHelper.getPropertyId(SETTINGS, "update_timestamp");
+
+ /**
+ * The property ids for setting resource.
+ */
+ private static final Set<String> propertyIds = new HashSet<>();
+
+ /**
+ * The key property ids for setting resource.
+ */
+ private static final Map<Resource.Type, String> keyPropertyIds = new HashMap<>();
+
+ private static final Set<String> requiredProperties = new HashSet<>();
+
+ @Inject
+ private static SettingDAO dao;
+
+ static {
+ propertyIds.add(SETTING_NAME_PROPERTY_ID);
+ propertyIds.add(SETTING_SETTING_TYPE_PROPERTY_ID);
+ propertyIds.add(SETTING_CONTENT_PROPERTY_ID);
+ propertyIds.add(SETTING_UPDATED_BY_PROPERTY_ID);
+ propertyIds.add(SETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+ propertyIds.add(SETTING_SETTING_TYPE_PROPERTY_ID);
+ propertyIds.add(SETTING);
+
+ keyPropertyIds.put(Resource.Type.Setting, SETTING_NAME_PROPERTY_ID);
+
+ requiredProperties.add(SETTING_NAME_PROPERTY_ID);
+ requiredProperties.add(SETTING_SETTING_TYPE_PROPERTY_ID);
+ requiredProperties.add(SETTING_CONTENT_PROPERTY_ID);
+ }
+
+ protected SettingResourceProvider() {
+ super(propertyIds, keyPropertyIds);
+ EnumSet<RoleAuthorization> requiredAuthorizations = EnumSet.of(RoleAuthorization.AMBARI_MANAGE_SETTINGS);
+ setRequiredCreateAuthorizations(requiredAuthorizations);
+ setRequiredDeleteAuthorizations(requiredAuthorizations);
+ setRequiredUpdateAuthorizations(requiredAuthorizations);
+ }
+
+ @Override
+ protected Set<String> getPKPropertyIds() {
+ return new HashSet<>(keyPropertyIds.values());
+ }
+
+ @Override
+ public RequestStatus createResourcesAuthorized(Request request)
+ throws NoSuchParentResourceException, ResourceAlreadyExistsException, SystemException {
+ Set<Resource> associatedResources = new HashSet<>();
+
+ for (Map<String, Object> properties : request.getProperties()) {
+ SettingEntity settingEntity = createResources(newCreateCommand(request, properties));
+ Resource resource = new ResourceImpl(Resource.Type.Setting);
+ resource.setProperty(SETTING_NAME_PROPERTY_ID, settingEntity.getName());
+ associatedResources.add(resource);
+ }
+
+ return getRequestStatus(null, associatedResources);
+ }
+
+ @Override
+ public Set<Resource> getResourcesAuthorized(Request request, Predicate predicate) throws NoSuchResourceException {
+ List<SettingEntity> 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(SETTING_NAME_PROPERTY_ID)) {
+ String name = propertyMap.get(SETTING_NAME_PROPERTY_ID).toString();
+ SettingEntity entity = dao.findByName(name);
+ if (entity == null) {
+ throw new NoSuchResourceException(String.format("Setting 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(SettingEntity entity : entities) {
+ resources.add(toResource(entity, requestedIds));
+ }
+ return resources;
+ }
+
+ @Override
+ public RequestStatus updateResourcesAuthorized(Request request, Predicate predicate)
+ throws NoSuchResourceException, NoSuchParentResourceException, SystemException {
+ modifyResources(newUpdateCommand(request));
+ return getRequestStatus(null);
+ }
+
+ @Override
+ public RequestStatus deleteResourcesAuthorized(Predicate predicate) {
+ final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
+ for (Map<String, Object> propertyMap : propertyMaps) {
+ if (propertyMap.containsKey(SETTING_NAME_PROPERTY_ID)) {
+ dao.removeByName(propertyMap.get(SETTING_NAME_PROPERTY_ID).toString());
+ }
+ }
+ return getRequestStatus(null);
+ }
+
+
+ private Command<SettingEntity> newCreateCommand(final Request request, final Map<String, Object> properties) {
+ return new Command<SettingEntity>() {
+ @Override
+ public SettingEntity invoke() throws AmbariException, AuthorizationException {
+ SettingEntity entity = toEntity(properties);
+ if (dao.findByName(entity.getName()) != null) {
+ throw new DuplicateResourceException(
+ String.format("Setting already exists. setting name :%s ", entity.getName()));
+ }
+ dao.create(entity);
+ notifyCreate(Resource.Type.Setting, 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(SETTING_NAME_PROPERTY_ID)) {
+ String name = propertyMap.get(SETTING_NAME_PROPERTY_ID).toString();
+ SettingEntity entity = dao.findByName(name);
+ if (entity == null) {
+ throw new AmbariException(String.format("There is no setting with name: %s ", name));
+ }
+ updateEntity(entity, propertyMap);
+ dao.merge(entity);
+ }
+ }
+ return null;
+ }
+ };
+ }
+
+ private void updateEntity(SettingEntity entity, Map<String, Object> propertyMap) throws AmbariException {
+ String name = propertyMap.get(SETTING_NAME_PROPERTY_ID).toString();
+ if (!Objects.equals(name, entity.getName())) {
+ throw new AmbariException("Name for Setting is immutable, cannot change name.");
+ }
+
+ if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(SETTING_CONTENT_PROPERTY_ID)))) {
+ entity.setContent(propertyMap.get(SETTING_CONTENT_PROPERTY_ID).toString());
+ }
+
+ if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(SETTING_SETTING_TYPE_PROPERTY_ID)))) {
+ entity.setSettingType(propertyMap.get(SETTING_SETTING_TYPE_PROPERTY_ID).toString());
+ }
+
+ entity.setUpdatedBy(AuthorizationHelper.getAuthenticatedName());
+ entity.setUpdateTimestamp(System.currentTimeMillis());
+ }
+
+ private Resource toResource(final SettingEntity settingEntity, final Set<String> requestedIds) {
+ Resource resource = new ResourceImpl(Resource.Type.Setting);
+ setResourceProperty(resource, SETTING_NAME_PROPERTY_ID, settingEntity.getName(), requestedIds);
+ setResourceProperty(resource, SETTING_SETTING_TYPE_PROPERTY_ID, settingEntity.getSettingType(), requestedIds);
+ setResourceProperty(resource, SETTING_CONTENT_PROPERTY_ID, settingEntity.getContent(), requestedIds);
+ setResourceProperty(resource, SETTING_UPDATED_BY_PROPERTY_ID, settingEntity.getUpdatedBy(), requestedIds);
+ setResourceProperty(resource, SETTING_UPDATE_TIMESTAMP_PROPERTY_ID, settingEntity.getUpdateTimestamp(), requestedIds);
+ return resource;
+ }
+
+ private SettingEntity 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));
+ }
+ }
+
+ SettingEntity entity = new SettingEntity();
+ entity.setName(properties.get(SETTING_NAME_PROPERTY_ID).toString());
+ entity.setSettingType(properties.get(SETTING_SETTING_TYPE_PROPERTY_ID).toString());
+ entity.setContent(properties.get(SETTING_CONTENT_PROPERTY_ID).toString());
+ entity.setUpdatedBy(AuthorizationHelper.getAuthenticatedName());
+ entity.setUpdateTimestamp(System.currentTimeMillis());
+ return entity;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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 9d6af76..f5fa5f1 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
@@ -76,7 +76,7 @@ public interface Resource {
enum InternalType {
Cluster,
Service,
- AdminSetting,
+ Setting,
Host,
Component,
HostComponent,
@@ -187,7 +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 Setting = InternalType.Setting.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/774d689e/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
deleted file mode 100644
index 30e032f..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AdminSettingDAO.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * 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/774d689e/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/SettingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/SettingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/SettingDAO.java
new file mode 100644
index 0000000..2d0da20
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/SettingDAO.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.SettingEntity;
+import org.apache.commons.lang.StringUtils;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+@Singleton
+public class SettingDAO {
+
+ @Inject
+ Provider<EntityManager> entityManagerProvider;
+ @Inject
+ DaoUtils daoUtils;
+
+ /**
+ * Find a setting with the given name.
+ *
+ * @param name - name of setting.
+ * @return a matching setting or null
+ */
+ @RequiresSession
+ public SettingEntity findByName(String name) {
+ if (StringUtils.isBlank(name)) {
+ return null;
+ }
+ TypedQuery<SettingEntity> query = entityManagerProvider.get()
+ .createNamedQuery("settingByName", SettingEntity.class);
+ query.setParameter("name", name);
+ return daoUtils.selectOne(query);
+ }
+
+ /**
+ * Find all settings.
+ *
+ * @return all setting instances.
+ */
+ @RequiresSession
+ public List<SettingEntity> findAll() {
+ return daoUtils.selectAll(entityManagerProvider.get(), SettingEntity.class);
+ }
+
+ /**
+ * Create a new setting entity.
+ *
+ * @param entity - entity to be created
+ */
+ @Transactional
+ public void create(SettingEntity entity) {
+ entityManagerProvider.get().persist(entity);
+ }
+
+ /**
+ * Update setting instance.
+ *
+ * @param entity - entity to be updated.
+ * @return - updated entity.
+ */
+ @Transactional
+ public SettingEntity merge(SettingEntity entity) {
+ return entityManagerProvider.get().merge(entity);
+ }
+
+ /**
+ * Delete setting with given name.
+ *
+ * @param name - name of setting to be deleted.
+ */
+ @Transactional
+ public void removeByName(String name) {
+ SettingEntity entity = findByName(name);
+ if (entity!= null) {
+ entityManagerProvider.get().remove(entity);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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
deleted file mode 100644
index 9edc7b5..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AdminSettingEntity.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/**
- * 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/774d689e/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.java
new file mode 100644
index 0000000..20820cd
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.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 Setting.
+ */
+@Table(name = "setting")
+@TableGenerator(name = "setting_id_generator",
+ table = "ambari_sequences", pkColumnName = "sequence_name", valueColumnName = "sequence_value",
+ pkColumnValue = "setting_id_seq", initialValue = 0)
+
+@NamedQuery(name = "settingByName", query = "SELECT setting FROM SettingEntity setting WHERE setting.name=:name")
+@Entity
+public class SettingEntity {
+ @Id
+ @Column(name = "id", nullable = false, insertable = true, updatable = false)
+ @GeneratedValue(strategy = GenerationType.TABLE, generator = "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 SettingEntity() {
+ }
+
+ 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 SettingEntity clone() {
+ SettingEntity cloned = new SettingEntity();
+ 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;
+
+ SettingEntity entity = (SettingEntity) 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/774d689e/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
index 1935d83..a77263d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/RoleAuthorization.java
@@ -32,7 +32,7 @@ public enum RoleAuthorization {
AMBARI_ADD_DELETE_CLUSTERS("AMBARI.ADD_DELETE_CLUSTERS"),
AMBARI_ASSIGN_ROLES("AMBARI.ASSIGN_ROLES"),
AMBARI_EDIT_STACK_REPOS("AMBARI.EDIT_STACK_REPOS"),
- AMBARI_MANAGE_ADMIN_SETTINGS("AMBARI.MANAGE_ADMIN_SETTINGS"),
+ AMBARI_MANAGE_SETTINGS("AMBARI.MANAGE_SETTINGS"),
AMBARI_MANAGE_GROUPS("AMBARI.MANAGE_GROUPS"),
AMBARI_MANAGE_STACK_VERSIONS("AMBARI.MANAGE_STACK_VERSIONS"),
AMBARI_MANAGE_USERS("AMBARI.MANAGE_USERS"),
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index 9982c2a..0fdfd2b 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -655,7 +655,7 @@ CREATE TABLE topology_logical_task (
PRIMARY KEY (id)
);
-CREATE TABLE adminsetting (
+CREATE TABLE setting (
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
setting_type VARCHAR(255) NOT NULL,
@@ -1033,7 +1033,7 @@ INSERT INTO ambari_sequences (sequence_name, sequence_value)
union all
select 'topology_host_group_id_seq', 0 FROM SYSIBM.SYSDUMMY1
union all
- select 'admin_setting_id_seq', 0 FROM SYSIBM.SYSDUMMY1
+ select 'setting_id_seq', 0 FROM SYSIBM.SYSDUMMY1
union all
select 'hostcomponentstate_id_seq', 0 FROM SYSIBM.SYSDUMMY1;
@@ -1111,7 +1111,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 'AMBARI.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' FROM SYSIBM.SYSDUMMY1 UNION ALL
- SELECT 'AMBARI.MANAGE_ADMIN_SETTINGS', 'Manage administrative settings' FROM SYSIBM.SYSDUMMY1 UNION ALL
+ SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 'AMBARI.MANAGE_USERS', 'Manage users' FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' FROM SYSIBM.SYSDUMMY1 UNION ALL
SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' FROM SYSIBM.SYSDUMMY1 UNION ALL
@@ -1292,7 +1292,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.SET_SERVICE_USERS_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_ADMIN_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+ SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index f05ebd2..11e43c2 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -662,7 +662,7 @@ CREATE TABLE topology_logical_task (
PRIMARY KEY (id)
);
-CREATE TABLE adminsetting (
+CREATE TABLE setting (
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
setting_type VARCHAR(255) NOT NULL,
@@ -997,7 +997,7 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_lo
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_logical_task_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_request_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_host_group_id_seq', 0);
-INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('admin_setting_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('setting_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostcomponentstate_id_seq', 0);
insert into adminresourcetype (resource_type_id, resource_type_name)
@@ -1076,7 +1076,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
SELECT 'AMBARI.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' UNION ALL
SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
- SELECT 'AMBARI.MANAGE_ADMIN_SETTINGS', 'Manage administrative settings' UNION ALL
+ SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage administrative settings' UNION ALL
SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1263,7 +1263,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.SET_SERVICE_USERS_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_ADMIN_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+ SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 96ef3fa..8d4ba28 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -651,7 +651,7 @@ CREATE TABLE topology_logical_task (
PRIMARY KEY (id)
);
-CREATE TABLE adminsetting (
+CREATE TABLE setting (
id NUMBER(19) NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
setting_type VARCHAR(255) NOT NULL,
@@ -987,7 +987,7 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_lo
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_logical_task_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_request_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_host_group_id_seq', 0);
-INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('admin_setting_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('setting_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostcomponentstate_id_seq', 0);
INSERT INTO metainfo("metainfo_key", "metainfo_value") values ('version', '${ambariVersion}');
@@ -1068,7 +1068,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' FROM dual UNION ALL
SELECT 'AMBARI.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' FROM dual UNION ALL
SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' FROM dual UNION ALL
- SELECT 'AMBARI.MANAGE_ADMIN_SETTINGS', 'Manage administrative settings' FROM dual UNION ALL
+ SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' FROM dual UNION ALL
SELECT 'AMBARI.MANAGE_USERS', 'Manage users' FROM dual UNION ALL
SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' FROM dual UNION ALL
SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' FROM dual UNION ALL
@@ -1255,7 +1255,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.SET_SERVICE_USERS_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_ADMIN_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+ SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 8bd9d03..c762ac4 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -655,7 +655,7 @@ CREATE TABLE topology_logical_task (
PRIMARY KEY (id)
);
-CREATE TABLE adminsetting (
+CREATE TABLE setting (
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
setting_type VARCHAR(255) NOT NULL,
@@ -1033,7 +1033,7 @@ INSERT INTO ambari_sequences (sequence_name, sequence_value)
union all
select 'topology_host_group_id_seq', 0
union all
- select 'admin_setting_id_seq', 0
+ select 'setting_id_seq', 0
union all
select 'hostcomponentstate_id_seq', 0;
@@ -1113,7 +1113,7 @@ INSERT INTO roleauthorization(authorization_id, authorization_name)
SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
SELECT 'AMBARI.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' UNION ALL
SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
- SELECT 'AMBARI.MANAGE_ADMIN_SETTINGS', 'Manage administrative settings' UNION ALL
+ SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage administrative settings' UNION ALL
SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1300,7 +1300,7 @@ INSERT INTO permission_roleauthorization(permission_id, authorization_id)
SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.SET_SERVICE_USERS_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_ADMIN_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+ SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index 54999cb..81b41fe 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -736,7 +736,7 @@ CREATE TABLE ambari.topology_logical_task (
);
GRANT ALL PRIVILEGES ON TABLE ambari.topology_logical_task TO :username;
-CREATE TABLE ambari.adminsetting (
+CREATE TABLE ambari.setting (
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
setting_type VARCHAR(255) NOT NULL,
@@ -745,7 +745,7 @@ CREATE TABLE ambari.adminsetting (
update_timestamp BIGINT NOT NULL,
PRIMARY KEY (id)
);
-GRANT ALL PRIVILEGES ON TABLE ambari.adminsetting TO :username;
+GRANT ALL PRIVILEGES ON TABLE ambari.setting TO :username;
-- tasks indices --
CREATE INDEX idx_stage_request_id ON ambari.stage (request_id);
@@ -1132,7 +1132,7 @@ INSERT INTO ambari.ambari_sequences (sequence_name, sequence_value)
union all
select 'topology_host_group_id_seq', 0
union all
- select 'admin_setting_id_seq', 0
+ select 'setting_id_seq', 0
union all
select 'hostcomponentstate_id_seq', 0;
@@ -1212,7 +1212,7 @@ INSERT INTO ambari.roleauthorization(authorization_id, authorization_name)
SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
SELECT 'AMBARI.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' UNION ALL
SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
- SELECT 'AMBARI.MANAGE_ADMIN_SETTINGS', 'Manage administrative settings' UNION ALL
+ SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' UNION ALL
SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1399,7 +1399,7 @@ INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.SET_SERVICE_USERS_GROUPS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_ADMIN_SETTINGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+ SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index ce058e2..f8c9b8d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -652,7 +652,7 @@ CREATE TABLE topology_logical_task (
PRIMARY KEY (id)
);
-CREATE TABLE adminsetting (
+CREATE TABLE setting (
id NUMERIC(19) NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
setting_type VARCHAR(255) NOT NULL,
@@ -984,7 +984,7 @@ INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_lo
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_logical_task_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_request_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('topology_host_group_id_seq', 0);
-INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('admin_setting_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('setting_id_seq', 0);
INSERT INTO ambari_sequences(sequence_name, sequence_value) values ('hostcomponentstate_id_seq', 0);
insert into adminresourcetype (resource_type_id, resource_type_name)
@@ -1063,7 +1063,7 @@ insert into adminpermission(permission_id, permission_name, resource_type_id, pe
SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
SELECT 'AMBARI.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' UNION ALL
SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
- SELECT 'AMBARI.MANAGE_ADMIN_SETTINGS', 'Manage administrative settings' UNION ALL
+ SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' UNION ALL
SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1250,7 +1250,7 @@ insert into adminpermission(permission_id, permission_name, resource_type_id, pe
SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.SET_SERVICE_USERS_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_ADMIN_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+ SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index 66ea512..324c24d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -760,7 +760,7 @@ CREATE TABLE topology_logical_task (
PRIMARY KEY CLUSTERED (id)
);
-CREATE TABLE adminsetting (
+CREATE TABLE setting (
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
setting_type VARCHAR(255) NOT NULL,
@@ -1100,7 +1100,7 @@ BEGIN TRANSACTION
('topology_logical_task_id_seq', 0),
('topology_request_id_seq', 0),
('topology_host_group_id_seq', 0),
- ('admin_setting_id_seq', 0),
+ ('setting_id_seq', 0),
('hostcomponentstate_id_seq', 0);
insert into adminresourcetype (resource_type_id, resource_type_name)
@@ -1173,7 +1173,7 @@ BEGIN TRANSACTION
SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
SELECT 'AMBARI.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' UNION ALL
SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
- SELECT 'AMBARI.MANAGE_ADMIN_SETTINGS', 'Manage administrative settings' UNION ALL
+ SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' UNION ALL
SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
@@ -1360,7 +1360,7 @@ BEGIN TRANSACTION
SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.SET_SERVICE_USERS_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_ADMIN_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
+ SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/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 280b9b6..7fd0391 100644
--- a/ambari-server/src/main/resources/META-INF/persistence.xml
+++ b/ambari-server/src/main/resources/META-INF/persistence.xml
@@ -88,7 +88,7 @@
<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.SettingEntity</class>
<class>org.apache.ambari.server.orm.entities.KerberosDescriptorEntity</class>
<properties>
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/api/services/AdminSettingServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AdminSettingServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AdminSettingServiceTest.java
deleted file mode 100644
index d84c97d..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AdminSettingServiceTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * 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.api.services.parsers.RequestBodyParser;
-import org.apache.ambari.server.api.services.serializers.ResultSerializer;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.UriInfo;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Unit test for {@link AdminSettingService}
- */
-public class AdminSettingServiceTest extends BaseServiceTest {
- @Override
- public List<ServiceTestInvocation> getTestInvocations() throws Exception {
- List<ServiceTestInvocation> listInvocations = new ArrayList<>();
-
- //getSetting
- AdminSettingService adminSettingService = new TestAdminSettingService("settingName");
- Method m = adminSettingService.getClass().getMethod("getSetting", String.class, HttpHeaders.class, UriInfo.class, String.class);
- Object[] args = new Object[] {null, getHttpHeaders(), getUriInfo(), "settingName"};
- listInvocations.add(new ServiceTestInvocation(Request.Type.GET, adminSettingService, m, args, null));
-
- //getSettings
- adminSettingService = new TestAdminSettingService(null);
- m = adminSettingService.getClass().getMethod("getSettings", String.class, HttpHeaders.class, UriInfo.class);
- args = new Object[] {null, getHttpHeaders(), getUriInfo()};
- listInvocations.add(new ServiceTestInvocation(Request.Type.GET, adminSettingService, m, args, null));
-
- //createSetting
- adminSettingService = new TestAdminSettingService(null);
- m = adminSettingService.getClass().getMethod("createSetting", String.class, HttpHeaders.class, UriInfo.class);
- args = new Object[] {"body", getHttpHeaders(), getUriInfo()};
- listInvocations.add(new ServiceTestInvocation(Request.Type.POST, adminSettingService, m, args, "body"));
-
- //updateSetting
- adminSettingService = new TestAdminSettingService("settingName");
- m = adminSettingService.getClass().getMethod("updateSetting", String.class, HttpHeaders.class, UriInfo.class, String.class);
- args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "settingName"};
- listInvocations.add(new ServiceTestInvocation(Request.Type.PUT, adminSettingService, m, args, "body"));
-
- //deleteSetting
- adminSettingService = new TestAdminSettingService("settingName");
- m = adminSettingService.getClass().getMethod("deleteSetting", HttpHeaders.class, UriInfo.class, String.class);
- args = new Object[] {getHttpHeaders(), getUriInfo(), "settingName"};
- listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, adminSettingService, m, args, null));
-
- return listInvocations;
- }
-
- private class TestAdminSettingService extends AdminSettingService {
- private String adminSettingName;
-
- private TestAdminSettingService(String settingName) {
- this.adminSettingName = settingName;
- }
-
- @Override
- ResourceInstance createSettingResource(String settingName) {
- assertEquals(this.adminSettingName, settingName);
- return getTestResource();
- }
-
- @Override
- RequestFactory getRequestFactory() {
- return getTestRequestFactory();
- }
-
- @Override
- protected RequestBodyParser getBodyParser() {
- return getTestBodyParser();
- }
-
- @Override
- protected ResultSerializer getResultSerializer() {
- return getTestResultSerializer();
- }
- }
-}