diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java index 2536d8b3a0a..b1cf3813b53 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java @@ -101,7 +101,8 @@ public class ConfigGroupImpl implements ConfigGroup { @AssistedInject public ConfigGroupImpl(@Assisted("cluster") Cluster cluster, @Assisted("serviceGroupId") @Nullable Long serviceGroupId, - @Assisted("serviceId") @Nullable Long serviceId, @Assisted("name") String name, + @Assisted("serviceId") @Nullable Long serviceId, + @Assisted("name") String name, @Assisted("tag") String tag, @Assisted("description") String description, @Assisted("configs") Map configurations, @Assisted("hosts") Map hosts, Clusters clusters, ConfigFactory configFactory, 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 0d9753ddd4a..16b648b1fb2 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -137,7 +137,6 @@ CREATE TABLE servicegroups ( id BIGINT NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, - stack_id BIGINT NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id)); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java index 0485396e512..158ab7df4fc 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java @@ -64,6 +64,7 @@ import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.Host; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.configgroup.ConfigGroup; import org.apache.ambari.server.state.configgroup.ConfigGroupFactory; import org.easymock.Capture; @@ -82,6 +83,8 @@ public class ConfigGroupResourceProviderTest { + public static final String SERVICE_GROUP_NAME = "default"; + public static final String SERVICE_NAME = "ZOOKEEPER"; private HostDAO hostDAO = null; @Before @@ -154,6 +157,7 @@ private void testCreateConfigGroup(Authentication authentication) throws Excepti HostEntity hostEntity2 = createMock(HostEntity.class); ConfigGroupFactory configGroupFactory = createNiceMock(ConfigGroupFactory.class); ConfigGroup configGroup = createNiceMock(ConfigGroup.class); + Service service = createNiceMock(Service.class); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); @@ -161,6 +165,8 @@ private void testCreateConfigGroup(Authentication authentication) throws Excepti expect(clusters.getHost("h2")).andReturn(h2); expect(cluster.getClusterName()).andReturn("Cluster100").anyTimes(); expect(cluster.isConfigTypeExists(anyString())).andReturn(true).anyTimes(); + expect(cluster.getService(SERVICE_GROUP_NAME, SERVICE_NAME)).andReturn(service); + expect(service.getServiceId()).andReturn(1L); expect(managementController.getConfigGroupFactory()).andReturn(configGroupFactory); expect(managementController.getAuthName()).andReturn("admin").anyTimes(); expect(hostDAO.findByName("h1")).andReturn(hostEntity1).atLeastOnce(); @@ -172,7 +178,6 @@ private void testCreateConfigGroup(Authentication authentication) throws Excepti Capture serviceName = newCapture(); Capture servcieId = newCapture(); Capture servcieGroupId = newCapture(); - Capture captureName = newCapture(); Capture captureDesc = newCapture(); Capture captureTag = newCapture(); Capture> captureConfigs = newCapture(); @@ -182,7 +187,7 @@ private void testCreateConfigGroup(Authentication authentication) throws Excepti capture(captureTag), capture(captureDesc), capture(captureConfigs), capture(captureHosts))).andReturn(configGroup); - replay(managementController, clusters, cluster, configGroupFactory, + replay(managementController, clusters, cluster, service, configGroupFactory, configGroup, response, hostDAO, hostEntity1, hostEntity2); ResourceProvider provider = getConfigGroupResourceProvider @@ -218,6 +223,8 @@ private void testCreateConfigGroup(Authentication authentication) throws Excepti hostSet); properties.put(ConfigGroupResourceProvider.CONFIGGROUP_CONFIGS_PROPERTY_ID, configSet); + properties.put(ConfigGroupResourceProvider.CONFIGGROUP_SERVICEGROUPNAME_PROPERTY_ID, SERVICE_GROUP_NAME); + properties.put(ConfigGroupResourceProvider.CONFIGGROUP_SERVICENAME_PROPERTY_ID, SERVICE_NAME); propertySet.add(properties); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java index 1296be987ae..062389a7804 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java @@ -27,11 +27,17 @@ 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.dao.ClusterDAO; +import org.apache.ambari.server.orm.dao.ClusterServiceDAO; import org.apache.ambari.server.orm.dao.ConfigGroupDAO; import org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO; +import org.apache.ambari.server.orm.dao.ServiceGroupDAO; +import org.apache.ambari.server.orm.entities.ClusterEntity; +import org.apache.ambari.server.orm.entities.ClusterServiceEntity; import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity; import org.apache.ambari.server.orm.entities.ConfigGroupEntity; import org.apache.ambari.server.orm.entities.ConfigGroupHostMappingEntity; +import org.apache.ambari.server.orm.entities.ServiceGroupEntity; import org.apache.ambari.server.state.configgroup.ConfigGroup; import org.apache.ambari.server.state.configgroup.ConfigGroupFactory; import org.junit.After; @@ -54,6 +60,9 @@ public class ConfigGroupTest { private ConfigFactory configFactory; private ConfigGroupDAO configGroupDAO; private ConfigGroupHostMappingDAO configGroupHostMappingDAO; + private ClusterDAO clusterDAO; + private ClusterServiceDAO clusterServiceDAO; + private ServiceGroupDAO serviceGroupDAO; @Before public void setup() throws Exception { @@ -65,6 +74,9 @@ public void setup() throws Exception { configGroupDAO = injector.getInstance(ConfigGroupDAO.class); configGroupHostMappingDAO = injector.getInstance (ConfigGroupHostMappingDAO.class); + clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class); + clusterDAO = injector.getInstance(ClusterDAO.class); + serviceGroupDAO = injector.getInstance(ServiceGroupDAO.class); StackId stackId = new StackId("HDP-0.1"); OrmTestHelper helper = injector.getInstance(OrmTestHelper.class); @@ -105,7 +117,21 @@ ConfigGroup createConfigGroup() throws AmbariException { configs.put(config.getType(), config); hosts.put(host.getHostId(), host); - ConfigGroup configGroup = configGroupFactory.createNew(cluster, 1L, 1L, "HDFS", "", "New HDFS configs for h1", configs, hosts); + ClusterEntity clusterEntity = clusterDAO.findByName("foo"); + + ServiceGroupEntity serviceGroupEntity = new ServiceGroupEntity(); + serviceGroupEntity.setClusterEntity(clusterEntity); + serviceGroupEntity.setServiceGroupName("default"); + serviceGroupDAO.create(serviceGroupEntity); + + ClusterServiceEntity clusterServiceEntity = new ClusterServiceEntity(); + clusterServiceEntity.setClusterEntity(clusterEntity); + clusterServiceEntity.setServiceGroupEntity(serviceGroupEntity); + clusterServiceEntity.setServiceName("HDFS"); + clusterServiceEntity.setServiceType("HDFS"); + clusterServiceDAO.create(clusterServiceEntity); + + ConfigGroup configGroup = configGroupFactory.createNew(cluster, 1L, clusterServiceEntity.getServiceId(), "cg-test", "HDFS", "New HDFS configs for h1", configs, hosts); cluster.addConfigGroup(configGroup); return configGroup;