Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Config> configurations,
@Assisted("hosts") Map<Long, Host> hosts, Clusters clusters, ConfigFactory configFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -154,13 +157,16 @@ 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();
expect(clusters.getHost("h1")).andReturn(h1);
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();
Expand All @@ -172,7 +178,6 @@ private void testCreateConfigGroup(Authentication authentication) throws Excepti
Capture<String> serviceName = newCapture();
Capture<Long> servcieId = newCapture();
Capture<Long> servcieGroupId = newCapture();
Capture<String> captureName = newCapture();
Capture<String> captureDesc = newCapture();
Capture<String> captureTag = newCapture();
Capture<Map<String, Config>> captureConfigs = newCapture();
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down