http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java index ffca51d..62ce93b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java @@ -36,7 +36,6 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.StackId; @@ -128,24 +127,16 @@ public class ExecutionCommandWrapperTest { CONFIG_ATTRIBUTES = new HashMap<String, Map<String,String>>(); //Cluster level global config - Config globalConfig = configFactory.createNew(cluster1, GLOBAL_CONFIG, GLOBAL_CLUSTER, CONFIG_ATTRIBUTES); - globalConfig.setTag(CLUSTER_VERSION_TAG); - cluster1.addConfig(globalConfig); + configFactory.createNew(cluster1, GLOBAL_CONFIG, CLUSTER_VERSION_TAG, GLOBAL_CLUSTER, CONFIG_ATTRIBUTES); //Cluster level service config - Config serviceSiteConfigCluster = configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_SITE_CLUSTER, CONFIG_ATTRIBUTES); - serviceSiteConfigCluster.setTag(CLUSTER_VERSION_TAG); - cluster1.addConfig(serviceSiteConfigCluster); + configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, CLUSTER_VERSION_TAG, SERVICE_SITE_CLUSTER, CONFIG_ATTRIBUTES); //Service level service config - Config serviceSiteConfigService = configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_SITE_SERVICE, CONFIG_ATTRIBUTES); - serviceSiteConfigService.setTag(SERVICE_VERSION_TAG); - cluster1.addConfig(serviceSiteConfigService); + configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_VERSION_TAG, SERVICE_SITE_SERVICE, CONFIG_ATTRIBUTES); //Host level service config - Config serviceSiteConfigHost = configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_SITE_HOST, CONFIG_ATTRIBUTES); - serviceSiteConfigHost.setTag(HOST_VERSION_TAG); - cluster1.addConfig(serviceSiteConfigHost); + configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, HOST_VERSION_TAG, SERVICE_SITE_HOST, CONFIG_ATTRIBUTES); ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java index 90a4421..246c8b3 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java @@ -34,8 +34,8 @@ import org.apache.ambari.server.orm.OrmTestHelper; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; +import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.ConfigHelper; -import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.StackId; import org.junit.After; @@ -103,15 +103,11 @@ public class TestActionSchedulerThreading { Map<String, String> properties = new HashMap<String, String>(); Map<String, Map<String, String>> propertiesAttributes = new HashMap<String, Map<String, String>>(); + ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); + // foo-type for v1 on current stack properties.put("foo-property-1", "foo-value-1"); - Config c1 = new ConfigImpl(cluster, "foo-type", properties, propertiesAttributes, injector); - c1.setTag("version-1"); - c1.setStackId(stackId); - c1.setVersion(1L); - - cluster.addConfig(c1); - c1.persist(); + Config c1 = configFactory.createNew(cluster, "foo-type", "version-1", properties, propertiesAttributes); // make v1 "current" cluster.addDesiredConfig("admin", Sets.newHashSet(c1), "note-1"); @@ -122,12 +118,7 @@ public class TestActionSchedulerThreading { // save v2 // foo-type for v2 on new stack properties.put("foo-property-2", "foo-value-2"); - Config c2 = new ConfigImpl(cluster, "foo-type", properties, propertiesAttributes, injector); - c2.setTag("version-2"); - c2.setStackId(newStackId); - c2.setVersion(2L); - cluster.addConfig(c2); - c2.persist(); + Config c2 = configFactory.createNew(cluster, "foo-type", "version-2", properties, propertiesAttributes); // make v2 "current" cluster.addDesiredConfig("admin", Sets.newHashSet(c2), "note-2"); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java index 43503fa..fc2bca5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java @@ -193,11 +193,7 @@ public class HeartbeatTestHelper { cluster.setCurrentStackVersion(stackId); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config = cf.createNew(cluster, "cluster-env", configProperties, new HashMap<String, Map<String, String>>()); - config.setTag("version1"); - config.persist(); - - cluster.addConfig(config); + Config config = cf.createNew(cluster, "cluster-env", "version1", configProperties, new HashMap<String, Map<String, String>>()); cluster.addDesiredConfig("user", Collections.singleton(config)); helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java index 76ab45c..68e9993 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java @@ -159,10 +159,8 @@ public class TestHeartbeatMonitor { }}; ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); - Config config = configFactory.createNew(cluster, "hadoop-env", + Config config = configFactory.createNew(cluster, "hadoop-env", "version1", new HashMap<String,String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - config.setTag("version1"); - cluster.addConfig(config); cluster.addDesiredConfig("_test", Collections.singleton(config)); @@ -243,18 +241,15 @@ public class TestHeartbeatMonitor { }}; ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); - Config hadoopEnvConfig = configFactory.createNew(cluster, "hadoop-env", + Config hadoopEnvConfig = configFactory.createNew(cluster, "hadoop-env", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - Config hbaseEnvConfig = configFactory.createNew(cluster, "hbase-env", + Config hbaseEnvConfig = configFactory.createNew(cluster, "hbase-env", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - hadoopEnvConfig.setTag("version1"); - cluster.addConfig(hadoopEnvConfig); - hbaseEnvConfig.setTag("version1"); - cluster.addConfig(hbaseEnvConfig); + cluster.addDesiredConfig("_test", Collections.singleton(hadoopEnvConfig)); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java index 6533e1c..6640837 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java @@ -218,7 +218,7 @@ public class RecoveryConfigHelperTest { config.updateProperties(new HashMap<String, String>() {{ put(RecoveryConfigHelper.RECOVERY_ENABLED_KEY, "false"); }}); - config.persist(false); + config.save(); // Recovery config should be stale because of the above change. boolean isConfigStale = recoveryConfigHelper.isConfigStale(cluster.getClusterName(), DummyHostname1, http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java index e54a117..78b804c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java @@ -87,8 +87,8 @@ import org.apache.ambari.server.security.ldap.LdapBatchDto; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.ComponentInfo; +import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigHelper; -import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.MaintenanceState; @@ -610,6 +610,7 @@ public class AmbariManagementControllerImplTest { Cluster cluster = createNiceMock(Cluster.class); ActionManager actionManager = createNiceMock(ActionManager.class); ClusterRequest clusterRequest = createNiceMock(ClusterRequest.class); + Config config = createNiceMock(Config.class); // requests Set<ClusterRequest> setRequests = Collections.singleton(clusterRequest); @@ -632,18 +633,11 @@ public class AmbariManagementControllerImplTest { expect(clusters.getClusterById(1L)).andReturn(cluster).anyTimes(); expect(cluster.getClusterName()).andReturn("clusterOld").anyTimes(); expect(cluster.getConfigPropertiesTypes(anyObject(String.class))).andReturn(Maps.<PropertyInfo.PropertyType, Set<String>>newHashMap()).anyTimes(); - expect(cluster.getDesiredConfigByType(anyObject(String.class))).andReturn(new ConfigImpl("config-type") { - @Override - public Map<String, Map<String, String>> getPropertiesAttributes() { - return Maps.newHashMap(); - } - - @Override - public Map<String, String> getProperties() { - return configReqProps; - } - }).anyTimes(); + expect(config.getType()).andReturn("config-type").anyTimes(); + expect(config.getProperties()).andReturn(configReqProps).anyTimes(); + expect(config.getPropertiesAttributes()).andReturn(new HashMap<String,Map<String,String>>()).anyTimes(); + expect(cluster.getDesiredConfigByType(anyObject(String.class))).andReturn(config).anyTimes(); cluster.addSessionAttributes(anyObject(Map.class)); expectLastCall().once(); @@ -652,7 +646,7 @@ public class AmbariManagementControllerImplTest { expectLastCall(); // replay mocks - replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager); + replay(actionManager, cluster, clusters, config, injector, clusterRequest, sessionManager); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -660,7 +654,7 @@ public class AmbariManagementControllerImplTest { // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager); + verify(actionManager, cluster, clusters, config, injector, clusterRequest, sessionManager); } /** @@ -1224,6 +1218,80 @@ public class AmbariManagementControllerImplTest { } @Test + public void testGetHostComponents___ServiceComponentHostFilteredByMaintenanceState() throws Exception { + // member state mocks + Injector injector = createStrictMock(Injector.class); + Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>(); + StackId stack = createNiceMock(StackId.class); + + Cluster cluster = createNiceMock(Cluster.class); + final Host host = createNiceMock(Host.class); + Service service = createNiceMock(Service.class); + ServiceComponent component = createNiceMock(ServiceComponent.class); + MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class); + final ServiceComponentHost componentHost1 = createNiceMock(ServiceComponentHost.class); + ServiceComponentHostResponse response1 = createNiceMock(ServiceComponentHostResponse.class); + + // requests + ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( + "cluster1", null, "component1", "host1", null); + request1.setMaintenanceState("ON"); + + + Set<ServiceComponentHostRequest> setRequests = new HashSet<ServiceComponentHostRequest>(); + setRequests.add(request1); + + // expectations + // constructor init + injector.injectMembers(capture(controllerCapture)); + expect(injector.getInstance(Gson.class)).andReturn(null); + expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper); + expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(maintHelper.getEffectiveState( + anyObject(ServiceComponentHost.class), + anyObject(Host.class))).andReturn(MaintenanceState.IMPLIED_FROM_SERVICE).anyTimes(); + + // getHostComponent + expect(clusters.getCluster("cluster1")).andReturn(cluster); + expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)); + expect(clusters.getHostsForCluster((String) anyObject())).andReturn( + new HashMap<String, Host>() {{ + put("host1", host); + }}).anyTimes(); + + expect(cluster.getDesiredStackVersion()).andReturn(stack); + expect(cluster.getClusterName()).andReturn("cl1"); + expect(stack.getStackName()).andReturn("stackName"); + expect(stack.getStackVersion()).andReturn("stackVersion"); + + expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1"); + expect(cluster.getService("service1")).andReturn(service); + expect(service.getServiceComponent("component1")).andReturn(component); + expect(component.getName()).andReturn("component1").anyTimes(); + expect(component.getServiceComponentHosts()).andReturn(new HashMap<String, ServiceComponentHost>() {{ + put("host1", componentHost1); + }}); + + expect(componentHost1.convertToResponse(null)).andReturn(response1); + expect(componentHost1.getHostName()).andReturn("host1"); + + // replay mocks + replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, + service, component, componentHost1, response1); + + //test + AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); + setAmbariMetaInfo(ambariMetaInfo, controller); + + Set<ServiceComponentHostResponse> responses = controller.getHostComponents(setRequests); + + // assert and verify + assertSame(controller, controllerCapture.getValue()); + assertTrue(responses.size() == 1); + verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, componentHost1, response1); + } + + @Test public void testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundException() throws Exception { // member state mocks Injector injector = createStrictMock(Injector.class); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java index 66c0f181..298a85f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java @@ -122,7 +122,6 @@ import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.ConfigHelper; -import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.HostComponentAdminState; import org.apache.ambari.server.state.HostState; @@ -408,7 +407,6 @@ public class AmbariManagementControllerTest { ConfigGroup configGroup = configGroupFactory.createNew(cluster, name, tag, "", configMap, hostMap); - configGroup.persist(); cluster.addConfigGroup(configGroup); return configGroup.getId(); @@ -1281,6 +1279,15 @@ public class AmbariManagementControllerTest { assertEquals("false", ec.getCommandParams().get("command_retry_enabled")); Map<String, Set<String>> chInfo = ec.getClusterHostInfo(); assertTrue(chInfo.containsKey("namenode_host")); + assertFalse(ec.getCommandParams().containsKey("custom_folder")); + + ec = controller.getExecutionCommand(cluster, + s1.getServiceComponent("DATANODE").getServiceComponentHost(host1), + RoleCommand.START); + assertEquals(cluster1, ec.getClusterName()); + assertNotNull(ec.getCommandParams()); + assertTrue(ec.getCommandParams().containsKey("custom_folder")); + assertEquals("dashboards", ec.getCommandParams().get("custom_folder")); } @Test @@ -1931,10 +1938,8 @@ public class AmbariManagementControllerTest { Map<String, String> properties = new HashMap<String, String>(); Map<String, Map<String, String>> propertiesAttributes = new HashMap<String, Map<String,String>>(); - Config c1 = new ConfigImpl(cluster, "hdfs-site", properties, propertiesAttributes, injector); - c1.setTag("v1"); - cluster.addConfig(c1); - c1.persist(); + ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); + Config c1 = configFactory.createNew(cluster, "hdfs-site", "v1", properties, propertiesAttributes); configs.put(c1.getType(), c1); ServiceRequest r = new ServiceRequest(cluster1, serviceName, State.INSTALLED.toString()); @@ -1974,26 +1979,17 @@ public class AmbariManagementControllerTest { properties.put("a", "a1"); properties.put("b", "b1"); - Config c1 = new ConfigImpl(cluster, "hdfs-site", properties, propertiesAttributes, injector); + ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); + Config c1 = configFactory.createNew(cluster, "hdfs-site", "v1", properties, propertiesAttributes); properties.put("c", cluster1); properties.put("d", "d1"); - Config c2 = new ConfigImpl(cluster, "core-site", properties, propertiesAttributes, injector); - Config c3 = new ConfigImpl(cluster, "foo-site", properties, propertiesAttributes, injector); + + Config c2 = configFactory.createNew(cluster, "core-site", "v1", properties, propertiesAttributes); + Config c3 = configFactory.createNew(cluster, "foo-site", "v1", properties, propertiesAttributes); Map<String, String> mapRequestProps = new HashMap<String, String>(); mapRequestProps.put("context", "Called from a test"); - c1.setTag("v1"); - c2.setTag("v1"); - c3.setTag("v1"); - - cluster.addConfig(c1); - cluster.addConfig(c2); - cluster.addConfig(c3); - c1.persist(); - c2.persist(); - c3.persist(); - configs.put(c1.getType(), c1); configs.put(c2.getType(), c2); @@ -4201,27 +4197,20 @@ public class AmbariManagementControllerTest { cluster.setCurrentStackVersion(new StackId("HDP-2.0.6")); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config1 = cf.createNew(cluster, "global", + Config config1 = cf.createNew(cluster, "global", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String, String>>()); - config1.setTag("version1"); - Config config2 = cf.createNew(cluster, "core-site", + Config config2 = cf.createNew(cluster, "core-site", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version1"); - Config config3 = cf.createNew(cluster, "yarn-site", + Config config3 = cf.createNew(cluster, "yarn-site", "version1", new HashMap<String, String>() {{ put("test.password", "supersecret"); }}, new HashMap<String, Map<String,String>>()); - config3.setTag("version1"); - - cluster.addConfig(config1); - cluster.addConfig(config2); - cluster.addConfig(config3); Service hdfs = cluster.addService("HDFS"); Service mapred = cluster.addService("YARN"); @@ -4374,20 +4363,15 @@ public class AmbariManagementControllerTest { cluster.setCurrentStackVersion(new StackId("HDP-2.0.7")); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config1 = cf.createNew(cluster, "global", + Config config1 = cf.createNew(cluster, "global", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = cf.createNew(cluster, "core-site", + Config config2 = cf.createNew(cluster, "core-site", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version1"); - - cluster.addConfig(config1); - cluster.addConfig(config2); Service hdfs = cluster.addService("HDFS"); @@ -4479,19 +4463,15 @@ public class AmbariManagementControllerTest { cluster.setCurrentStackVersion(new StackId("HDP-2.0.7")); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config1 = cf.createNew(cluster, "global", + Config config1 = cf.createNew(cluster, "global", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = cf.createNew(cluster, "core-site", + Config config2 = cf.createNew(cluster, "core-site", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version1"); - config1.persist(); - config2.persist(); cluster.addConfig(config1); cluster.addConfig(config2); @@ -4767,18 +4747,14 @@ public class AmbariManagementControllerTest { cluster.setCurrentStackVersion(new StackId("HDP-0.1")); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config1 = cf.createNew(cluster, "global", + Config config1 = cf.createNew(cluster, "global", "version1", new HashMap<String, String>(){{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); config1.setPropertiesAttributes(new HashMap<String, Map<String, String>>(){{ put("attr1", new HashMap<String, String>()); }}); - Config config2 = cf.createNew(cluster, "core-site", + Config config2 = cf.createNew(cluster, "core-site", "version1", new HashMap<String, String>(){{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version1"); config2.setPropertiesAttributes(new HashMap<String, Map<String, String>>(){{ put("attr2", new HashMap<String, String>()); }}); - cluster.addConfig(config1); - cluster.addConfig(config2); cluster.addDesiredConfig("_test", Collections.singleton(config1)); cluster.addDesiredConfig("_test", Collections.singleton(config2)); @@ -5513,11 +5489,8 @@ public class AmbariManagementControllerTest { configs3, null); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config1 = cf.createNew(cluster, "kerberos-env", + Config config1 = cf.createNew(cluster, "kerberos-env", "version1", new HashMap<String, String>(), new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - - cluster.addConfig(config1); ClusterRequest crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null); crReq.setDesiredConfig(Collections.singletonList(cr1)); @@ -6439,20 +6412,15 @@ public class AmbariManagementControllerTest { cluster.setCurrentStackVersion(new StackId("HDP-2.0.6")); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config1 = cf.createNew(cluster, "global", + Config config1 = cf.createNew(cluster, "global", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = cf.createNew(cluster, "core-site", + Config config2 = cf.createNew(cluster, "core-site", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version1"); - - cluster.addConfig(config1); - cluster.addConfig(config2); Service hdfs = cluster.addService("HDFS"); Service mapred = cluster.addService("YARN"); @@ -6545,20 +6513,15 @@ public class AmbariManagementControllerTest { cluster.setCurrentStackVersion(new StackId("HDP-2.0.6")); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config1 = cf.createNew(cluster, "global", + Config config1 = cf.createNew(cluster, "global", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = cf.createNew(cluster, "core-site", + Config config2 = cf.createNew(cluster, "core-site", "version1", new HashMap<String, String>() {{ put("key1", "value1"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version1"); - - cluster.addConfig(config1); - cluster.addConfig(config2); Service hdfs = cluster.addService("HDFS"); Service mapred = cluster.addService("YARN"); @@ -6972,13 +6935,13 @@ public class AmbariManagementControllerTest { String group2 = getUniqueName(); String tag2 = getUniqueName(); + ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); + // Create Config group for core-site configs = new HashMap<String, String>(); configs.put("a", "c"); cluster = clusters.getCluster(cluster1); - final Config config = new ConfigImpl("core-site"); - config.setProperties(configs); - config.setTag("version122"); + final Config config = configFactory.createReadOnly("core-site", "version122", configs, null); Long groupId = createConfigGroup(cluster, group1, tag1, new ArrayList<String>() {{ add(host1); }}, new ArrayList<Config>() {{ add(config); }}); @@ -6989,9 +6952,7 @@ public class AmbariManagementControllerTest { configs = new HashMap<String, String>(); configs.put("a", "c"); - final Config config2 = new ConfigImpl("mapred-site"); - config2.setProperties(configs); - config2.setTag("version122"); + final Config config2 = configFactory.createReadOnly("mapred-site", "version122", configs, null); groupId = createConfigGroup(cluster, group2, tag2, new ArrayList<String>() {{ add(host1); }}, new ArrayList<Config>() {{ add(config2); }}); @@ -7056,7 +7017,6 @@ public class AmbariManagementControllerTest { ConfigGroup configGroup = cluster.getConfigGroups().get(groupId); configGroup.setHosts(new HashMap<Long, Host>() {{ put(3L, clusters.getHost(host3)); }}); - configGroup.persist(); requestId = startService(cluster1, serviceName2, false, false); mapredInstall = null; @@ -7134,9 +7094,8 @@ public class AmbariManagementControllerTest { String group1 = getUniqueName(); String tag1 = getUniqueName(); - final Config config = new ConfigImpl("hdfs-site"); - config.setProperties(configs); - config.setTag("version122"); + ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); + final Config config = configFactory.createReadOnly("hdfs-site", "version122", configs, null); Long groupId = createConfigGroup(clusters.getCluster(cluster1), group1, tag1, new ArrayList<String>() {{ add(host1); @@ -7244,9 +7203,8 @@ public class AmbariManagementControllerTest { configs = new HashMap<String, String>(); configs.put("a", "c"); - final Config config = new ConfigImpl("hdfs-site"); - config.setProperties(configs); - config.setTag("version122"); + ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); + final Config config = configFactory.createReadOnly("hdfs-site", "version122", configs, null); Long groupId = createConfigGroup(clusters.getCluster(cluster1), group1, tag1, new ArrayList<String>() {{ add(host1); add(host2); }}, new ArrayList<Config>() {{ add(config); }}); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java index f2dd099..02a2851 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java @@ -5919,6 +5919,10 @@ public class BlueprintConfigurationProcessorTest { hiveProperties.put("hive.exec.post.hooks", ""); properties.put("hive-site", hiveProperties); + Map<String, String> hiveEnv = new HashMap<String, String>(); + hiveEnv.put("hive.atlas.hook", "false"); + properties.put("hive-env", hiveEnv); + Map<String, Map<String, String>> parentProperties = new HashMap<String, Map<String, String>>(); Configuration parentClusterConfig = new Configuration(parentProperties, @@ -5996,6 +6000,9 @@ public class BlueprintConfigurationProcessorTest { hiveProperties.put("hive.exec.post.hooks", ""); properties.put("hive-site", hiveProperties); + Map<String, String> hiveEnv = new HashMap<String, String>(); + properties.put("hive-env", hiveEnv); + return properties; } @@ -6047,6 +6054,10 @@ public class BlueprintConfigurationProcessorTest { hiveProperties.put("hive.exec.post.hooks", "foo"); properties.put("hive-site", hiveProperties); + Map<String, String> hiveEnv = new HashMap<String, String>(); + hiveEnv.put("hive.atlas.hook", "false"); + properties.put("hive-env", hiveEnv); + Map<String, Map<String, String>> parentProperties = new HashMap<String, Map<String, String>>(); Configuration parentClusterConfig = new Configuration(parentProperties, http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java index 6f592cd..a96f395 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java @@ -657,6 +657,37 @@ public class CalculatedStatusTest { assertEquals(HostRoleStatus.IN_PROGRESS, calc.getStatus()); } + /** + * Tests that when there are no tasks and all counts are 0, that the returned + * status is {@link HostRoleStatus#COMPLETED}. + * + * @throws Exception + */ + @Test + public void testGetCompletedStatusForNoTasks() throws Exception { + // no status / no tasks + CalculatedStatus status = CalculatedStatus.statusFromTaskEntities( + new ArrayList<HostRoleCommandEntity>(), false); + + assertEquals(HostRoleStatus.COMPLETED, status.getStatus()); + + // empty summaries + status = CalculatedStatus.statusFromStageSummary( + new HashMap<Long, HostRoleCommandStatusSummaryDTO>(), new HashSet<Long>()); + + assertEquals(HostRoleStatus.COMPLETED, status.getStatus()); + + // generate a map of 0's - COMPLETED=0, IN_PROGRESS=0, etc + Map<HostRoleStatus, Integer> counts = CalculatedStatus.calculateStatusCounts(new ArrayList<HostRoleStatus>()); + Map<HostRoleStatus, Integer> displayCounts = CalculatedStatus.calculateStatusCounts(new ArrayList<HostRoleStatus>()); + + HostRoleStatus hostRoleStatus = CalculatedStatus.calculateSummaryStatusOfUpgrade(counts, 0); + HostRoleStatus hostRoleDisplayStatus = CalculatedStatus.calculateSummaryDisplayStatus(displayCounts, 0, false); + + assertEquals(HostRoleStatus.COMPLETED, hostRoleStatus); + assertEquals(HostRoleStatus.COMPLETED, hostRoleDisplayStatus); + } + private Collection<HostRoleCommandEntity> getTaskEntities(HostRoleStatus... statuses) { Collection<HostRoleCommandEntity> entities = new LinkedList<HostRoleCommandEntity>(); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java index 5dfc74d..f7dff11 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java @@ -20,11 +20,10 @@ package org.apache.ambari.server.controller.internal; import static org.apache.ambari.server.controller.internal.HostComponentResourceProvider.HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID; -import org.apache.ambari.server.topology.Blueprint; import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.eq; +import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.newCapture; import static org.powermock.api.easymock.PowerMock.createMock; import static org.powermock.api.easymock.PowerMock.createNiceMock; @@ -77,6 +76,7 @@ import org.apache.ambari.server.security.authorization.AuthorizationHelperInitia import org.apache.ambari.server.security.authorization.RoleAuthorization; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.topology.Blueprint; import org.apache.ambari.server.topology.ClusterTopology; import org.apache.ambari.server.topology.HostGroupInfo; import org.apache.ambari.server.topology.LogicalRequest; @@ -1200,7 +1200,7 @@ public class RequestResourceProviderTest { } } Assert.assertNotNull(propertyIdToAssert); - Assert.assertEquals("true", (String) propertyValueToAssert); + Assert.assertEquals("true", propertyValueToAssert); } @Test @@ -1624,6 +1624,12 @@ public class RequestResourceProviderTest { verify(managementController, actionManager, clusters, requestMock, requestDAO, hrcDAO); } + /** + * Tests that topology requests return different status (PENDING) if there are + * no tasks. Normal requests should return COMPLETED. + * + * @throws Exception + */ @Test @PrepareForTest(AmbariServer.class) public void testGetLogicalRequestStatusWithNoTasks() throws Exception { http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java index 96810cf..1747b28 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java @@ -66,7 +66,7 @@ import org.apache.ambari.server.security.authorization.RoleAuthorization; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.ConfigImpl; +import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.HostState; import org.apache.ambari.server.state.RepositoryVersionState; @@ -108,6 +108,7 @@ public class UpgradeResourceProviderHDP22Test { private AmbariManagementController amc; private StackDAO stackDAO; private TopologyManager topologyManager; + private ConfigFactory configFactory; private static final String configTagVersion1 = "version1"; private static final String configTagVersion2 = "version2"; @@ -136,6 +137,7 @@ public class UpgradeResourceProviderHDP22Test { stackDAO = injector.getInstance(StackDAO.class); upgradeDao = injector.getInstance(UpgradeDAO.class); repoVersionDao = injector.getInstance(RepositoryVersionDAO.class); + configFactory = injector.getInstance(ConfigFactory.class); AmbariEventPublisher publisher = createNiceMock(AmbariEventPublisher.class); replay(publisher); @@ -233,11 +235,7 @@ public class UpgradeResourceProviderHDP22Test { } } - Config config = new ConfigImpl("hive-site"); - config.setProperties(configTagVersion1Properties); - config.setTag(configTagVersion1); - - cluster.addConfig(config); + Config config = configFactory.createNew(cluster, "hive-site", configTagVersion1, configTagVersion1Properties, null); cluster.addDesiredConfig("admin", Collections.singleton(config)); Map<String, Object> requestProps = new HashMap<String, Object>(); @@ -286,9 +284,7 @@ public class UpgradeResourceProviderHDP22Test { // Hive service checks have generated the ExecutionCommands by now. // Change the new desired config tag and verify execution command picks up new tag assertEquals(configTagVersion1, cluster.getDesiredConfigByType("hive-site").getTag()); - final Config newConfig = new ConfigImpl("hive-site"); - newConfig.setProperties(configTagVersion2Properties); - newConfig.setTag(configTagVersion2); + final Config newConfig = configFactory.createNew(cluster, "hive-site", configTagVersion2, configTagVersion2Properties, null); Set<Config> desiredConfigs = new HashSet<Config>() { { add(newConfig); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java index d69bdbe..844331e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java @@ -85,8 +85,8 @@ import org.apache.ambari.server.serveraction.upgrades.AutoSkipFailedSummaryActio import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; +import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.ConfigHelper; -import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.HostState; @@ -144,6 +144,7 @@ public class UpgradeResourceProviderTest { private StackDAO stackDAO; private AmbariMetaInfo ambariMetaInfo; private TopologyManager topologyManager; + private ConfigFactory configFactory; @Before public void before() throws Exception { @@ -174,6 +175,7 @@ public class UpgradeResourceProviderTest { amc = injector.getInstance(AmbariManagementController.class); ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class); + configFactory = injector.getInstance(ConfigFactory.class); Field field = AmbariServer.class.getDeclaredField("clusterController"); field.setAccessible(true); @@ -1046,16 +1048,9 @@ public class UpgradeResourceProviderTest { } - Config config = new ConfigImpl("zoo.cfg"); - config.setProperties(new HashMap<String, String>() {{ - put("a", "b"); - }}); - config.setTag("abcdefg"); - - cluster.addConfig(config); + Config config = configFactory.createNew(cluster, "zoo.cfg", "abcdefg", Collections.singletonMap("a", "b"), null); cluster.addDesiredConfig("admin", Collections.singleton(config)); - Map<String, Object> requestProps = new HashMap<String, Object>(); requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1"); requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0"); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java index b58350b..a36ce0d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java @@ -23,7 +23,6 @@ import org.easymock.EasyMockSupport; import org.junit.Test; import java.util.Collections; -import java.util.HashSet; import java.util.Set; import java.util.concurrent.Executor; @@ -51,8 +50,7 @@ public class LogSearchDataRetrievalServiceTest { EasyMockSupport mockSupport = new EasyMockSupport(); - LoggingRequestHelperFactory helperFactoryMock = - mockSupport.createMock(LoggingRequestHelperFactory.class); + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); LoggingRequestHelper helperMock = mockSupport.createMock(LoggingRequestHelper.class); @@ -62,8 +60,7 @@ public class LogSearchDataRetrievalServiceTest { mockSupport.replayAll(); - LogSearchDataRetrievalService retrievalService = - new LogSearchDataRetrievalService(); + LogSearchDataRetrievalService retrievalService = new LogSearchDataRetrievalService(); retrievalService.setLoggingRequestHelperFactory(helperFactoryMock); // call the initialization routine called by the Google framework retrievalService.doStart(); @@ -71,8 +68,7 @@ public class LogSearchDataRetrievalServiceTest { String resultTailFileURI = retrievalService.getLogFileTailURI("http://localhost", expectedComponentName, expectedHostName, expectedClusterName); - assertEquals("TailFileURI was not returned as expected", - expectedResultURI, resultTailFileURI); + assertEquals("TailFileURI was not returned as expected", expectedResultURI, resultTailFileURI); mockSupport.verifyAll(); } @@ -85,8 +81,7 @@ public class LogSearchDataRetrievalServiceTest { EasyMockSupport mockSupport = new EasyMockSupport(); - LoggingRequestHelperFactory helperFactoryMock = - mockSupport.createMock(LoggingRequestHelperFactory.class); + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); // return null, to simulate the case where LogSearch Server is // not available for some reason @@ -94,8 +89,7 @@ public class LogSearchDataRetrievalServiceTest { mockSupport.replayAll(); - LogSearchDataRetrievalService retrievalService = - new LogSearchDataRetrievalService(); + LogSearchDataRetrievalService retrievalService = new LogSearchDataRetrievalService(); retrievalService.setLoggingRequestHelperFactory(helperFactoryMock); // call the initialization routine called by the Google framework retrievalService.doStart(); @@ -103,11 +97,9 @@ public class LogSearchDataRetrievalServiceTest { String resultTailFileURI = retrievalService.getLogFileTailURI("http://localhost", expectedComponentName, expectedHostName, expectedClusterName); - assertNull("TailFileURI should be null in this case", - resultTailFileURI); + assertNull("TailFileURI should be null in this case", resultTailFileURI); mockSupport.verifyAll(); - } @Test @@ -118,11 +110,9 @@ public class LogSearchDataRetrievalServiceTest { EasyMockSupport mockSupport = new EasyMockSupport(); - LoggingRequestHelperFactory helperFactoryMock = - mockSupport.createMock(LoggingRequestHelperFactory.class); + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); - Executor executorMock = - mockSupport.createMock(Executor.class); + Executor executorMock = mockSupport.createMock(Executor.class); // expect the executor to be called to execute the LogSearch request executorMock.execute(isA(LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable.class)); @@ -131,24 +121,19 @@ public class LogSearchDataRetrievalServiceTest { mockSupport.replayAll(); - LogSearchDataRetrievalService retrievalService = - new LogSearchDataRetrievalService(); + LogSearchDataRetrievalService retrievalService = new LogSearchDataRetrievalService(); retrievalService.setLoggingRequestHelperFactory(helperFactoryMock); // call the initialization routine called by the Google framework retrievalService.doStart(); retrievalService.setExecutor(executorMock); - assertEquals("Default request set should be empty", - 0, retrievalService.getCurrentRequests().size()); + assertEquals("Default request set should be empty", 0, retrievalService.getCurrentRequests().size()); - Set<String> resultSet = - retrievalService.getLogFileNames(expectedComponentName, expectedHostName, expectedClusterName); + Set<String> resultSet = retrievalService.getLogFileNames(expectedComponentName, expectedHostName, expectedClusterName); - assertNull("Inital query on the retrieval service should be null, since cache is empty by default", - resultSet); - assertEquals("Incorrect number of entries in the current request set", - 1, retrievalService.getCurrentRequests().size()); + assertNull("Inital query on the retrieval service should be null, since cache is empty by default", resultSet); + assertEquals("Incorrect number of entries in the current request set", 1, retrievalService.getCurrentRequests().size()); assertTrue("Incorrect HostComponent set on request set", retrievalService.getCurrentRequests().contains(expectedComponentName + "+" + expectedHostName)); @@ -163,16 +148,13 @@ public class LogSearchDataRetrievalServiceTest { EasyMockSupport mockSupport = new EasyMockSupport(); - LoggingRequestHelperFactory helperFactoryMock = - mockSupport.createMock(LoggingRequestHelperFactory.class); + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); - Executor executorMock = - mockSupport.createMock(Executor.class); + Executor executorMock = mockSupport.createMock(Executor.class); mockSupport.replayAll(); - LogSearchDataRetrievalService retrievalService = - new LogSearchDataRetrievalService(); + LogSearchDataRetrievalService retrievalService = new LogSearchDataRetrievalService(); retrievalService.setLoggingRequestHelperFactory(helperFactoryMock); // call the initialization routine called by the Google framework retrievalService.doStart(); @@ -184,16 +166,15 @@ public class LogSearchDataRetrievalServiceTest { // but is not yet completed. retrievalService.getCurrentRequests().add(expectedComponentName + "+" + expectedHostName); - Set<String> resultSet = - retrievalService.getLogFileNames(expectedComponentName, expectedHostName, expectedClusterName); + Set<String> resultSet = retrievalService.getLogFileNames(expectedComponentName, expectedHostName, expectedClusterName); - assertNull("Inital query on the retrieval service should be null, since cache is empty by default", - resultSet); + assertNull("Inital query on the retrieval service should be null, since cache is empty by default", resultSet); mockSupport.verifyAll(); } @Test + @SuppressWarnings("unchecked") public void testRunnableWithSuccessfulCall() throws Exception { final String expectedHostName = "c6401.ambari.apache.org"; final String expectedComponentName = "DATANODE"; @@ -202,17 +183,12 @@ public class LogSearchDataRetrievalServiceTest { EasyMockSupport mockSupport = new EasyMockSupport(); - LoggingRequestHelperFactory helperFactoryMock = - mockSupport.createMock(LoggingRequestHelperFactory.class); - AmbariManagementController controllerMock = - mockSupport.createMock(AmbariManagementController.class); - LoggingRequestHelper helperMock = - mockSupport.createMock(LoggingRequestHelper.class); + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); + AmbariManagementController controllerMock = mockSupport.createMock(AmbariManagementController.class); + LoggingRequestHelper helperMock = mockSupport.createMock(LoggingRequestHelper.class); - Cache cacheMock = - mockSupport.createMock(Cache.class); - Set currentRequestsMock = - mockSupport.createMock(Set.class); + Cache<String, Set<String>> cacheMock = mockSupport.createMock(Cache.class); + Set<String> currentRequestsMock = mockSupport.createMock(Set.class); expect(helperFactoryMock.getHelper(controllerMock, expectedClusterName)).andReturn(helperMock); expect(helperMock.sendGetLogFileNamesRequest(expectedComponentName, expectedHostName)).andReturn(Collections.singleton("/this/is/just/a/test/directory")); @@ -225,14 +201,14 @@ public class LogSearchDataRetrievalServiceTest { LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable loggingRunnable = new LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable(expectedHostName, expectedComponentName, expectedClusterName, - cacheMock, currentRequestsMock, helperFactoryMock, controllerMock); + cacheMock, currentRequestsMock, helperFactoryMock, controllerMock); loggingRunnable.run(); mockSupport.verifyAll(); - } @Test + @SuppressWarnings("unchecked") public void testRunnableWithFailedCallNullHelper() throws Exception { final String expectedHostName = "c6401.ambari.apache.org"; final String expectedComponentName = "DATANODE"; @@ -241,15 +217,11 @@ public class LogSearchDataRetrievalServiceTest { EasyMockSupport mockSupport = new EasyMockSupport(); - LoggingRequestHelperFactory helperFactoryMock = - mockSupport.createMock(LoggingRequestHelperFactory.class); - AmbariManagementController controllerMock = - mockSupport.createMock(AmbariManagementController.class); + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); + AmbariManagementController controllerMock = mockSupport.createMock(AmbariManagementController.class); - Cache cacheMock = - mockSupport.createMock(Cache.class); - Set currentRequestsMock = - mockSupport.createMock(Set.class); + Cache<String, Set<String>> cacheMock = mockSupport.createMock(Cache.class); + Set<String> currentRequestsMock = mockSupport.createMock(Set.class); // return null to simulate an error during helper instance creation expect(helperFactoryMock.getHelper(controllerMock, expectedClusterName)).andReturn(null); @@ -261,7 +233,7 @@ public class LogSearchDataRetrievalServiceTest { LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable loggingRunnable = new LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable(expectedHostName, expectedComponentName, expectedClusterName, - cacheMock, currentRequestsMock, helperFactoryMock, controllerMock); + cacheMock, currentRequestsMock, helperFactoryMock, controllerMock); loggingRunnable.run(); mockSupport.verifyAll(); @@ -269,6 +241,7 @@ public class LogSearchDataRetrievalServiceTest { } @Test + @SuppressWarnings("unchecked") public void testRunnableWithFailedCallNullResult() throws Exception { final String expectedHostName = "c6401.ambari.apache.org"; final String expectedComponentName = "DATANODE"; @@ -277,17 +250,12 @@ public class LogSearchDataRetrievalServiceTest { EasyMockSupport mockSupport = new EasyMockSupport(); - LoggingRequestHelperFactory helperFactoryMock = - mockSupport.createMock(LoggingRequestHelperFactory.class); - AmbariManagementController controllerMock = - mockSupport.createMock(AmbariManagementController.class); - LoggingRequestHelper helperMock = - mockSupport.createMock(LoggingRequestHelper.class); + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); + AmbariManagementController controllerMock = mockSupport.createMock(AmbariManagementController.class); + LoggingRequestHelper helperMock = mockSupport.createMock(LoggingRequestHelper.class); - Cache cacheMock = - mockSupport.createMock(Cache.class); - Set currentRequestsMock = - mockSupport.createMock(Set.class); + Cache<String, Set<String>> cacheMock = mockSupport.createMock(Cache.class); + Set<String> currentRequestsMock = mockSupport.createMock(Set.class); expect(helperFactoryMock.getHelper(controllerMock, expectedClusterName)).andReturn(helperMock); // return null to simulate an error occurring during the LogSearch data request @@ -300,11 +268,43 @@ public class LogSearchDataRetrievalServiceTest { LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable loggingRunnable = new LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable(expectedHostName, expectedComponentName, expectedClusterName, - cacheMock, currentRequestsMock, helperFactoryMock, controllerMock); + cacheMock, currentRequestsMock, helperFactoryMock, controllerMock); loggingRunnable.run(); mockSupport.verifyAll(); - } + @Test + @SuppressWarnings("unchecked") + public void testRunnableWithFailedCallEmptyResult() throws Exception { + final String expectedHostName = "c6401.ambari.apache.org"; + final String expectedComponentName = "DATANODE"; + final String expectedClusterName = "clusterone"; + final String expectedComponentAndHostName = expectedComponentName + "+" + expectedHostName; + + EasyMockSupport mockSupport = new EasyMockSupport(); + + LoggingRequestHelperFactory helperFactoryMock = mockSupport.createMock(LoggingRequestHelperFactory.class); + AmbariManagementController controllerMock = mockSupport.createMock(AmbariManagementController.class); + LoggingRequestHelper helperMock = mockSupport.createMock(LoggingRequestHelper.class); + + Cache<String, Set<String>> cacheMock = mockSupport.createMock(Cache.class); + Set<String> currentRequestsMock = mockSupport.createMock(Set.class); + + expect(helperFactoryMock.getHelper(controllerMock, expectedClusterName)).andReturn(helperMock); + // return null to simulate an error occurring during the LogSearch data request + expect(helperMock.sendGetLogFileNamesRequest(expectedComponentName, expectedHostName)).andReturn(Collections.EMPTY_SET); + // expect that the completed request is removed from the current request set, + // even in the event of a failure to obtain the LogSearch data + expect(currentRequestsMock.remove(expectedComponentAndHostName)).andReturn(true).once(); + + mockSupport.replayAll(); + + LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable loggingRunnable = + new LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable(expectedHostName, expectedComponentName, expectedClusterName, + cacheMock, currentRequestsMock, helperFactoryMock, controllerMock); + loggingRunnable.run(); + + mockSupport.verifyAll(); + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java index b839b64..12b5b69 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java @@ -122,6 +122,7 @@ public class LoggingRequestHelperImplTest { @Test public void testLogQueryRequestBasic() throws Exception { + LoggingCookieStore.INSTANCE.getCookiesMap().clear(); EasyMockSupport mockSupport = new EasyMockSupport(); @@ -301,6 +302,7 @@ public class LoggingRequestHelperImplTest { @Test public void testLogLevelRequestBasic() throws Exception { + LoggingCookieStore.INSTANCE.getCookiesMap().clear(); EasyMockSupport mockSupport = new EasyMockSupport(); @@ -391,6 +393,7 @@ public class LoggingRequestHelperImplTest { @Test public void testLogFileNameRequestBasic() throws Exception { + LoggingCookieStore.INSTANCE.getCookiesMap().clear(); final String expectedComponentName = "hdfs_namenode"; EasyMockSupport mockSupport = @@ -478,6 +481,7 @@ public class LoggingRequestHelperImplTest { */ @Test public void testLogQueryRequestBasicCredentialsNotInConfig() throws Exception { + LoggingCookieStore.INSTANCE.getCookiesMap().clear(); final String expectedClusterName = "my-test-cluster"; EasyMockSupport mockSupport = @@ -656,6 +660,7 @@ public class LoggingRequestHelperImplTest { @Test public void testCreateLogFileTailURI() throws Exception { + LoggingCookieStore.INSTANCE.getCookiesMap().clear(); final String expectedHostName = "c6401.ambari.apache.org"; final String expectedPort = "61888"; final String expectedComponentName = "hdfs_namenode"; http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java index 6773176..a4a9e26 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java @@ -90,6 +90,7 @@ public class InMemoryDefaultTestModule extends AbstractModule { String stacks = "src/test/resources/stacks"; String version = "src/test/resources/version"; String sharedResourcesDir = "src/test/resources/"; + String resourcesDir = "src/test/resources/"; if (System.getProperty("os.name").contains("Windows")) { stacks = ClassLoader.getSystemClassLoader().getResource("stacks").getPath(); version = new File(new File(ClassLoader.getSystemClassLoader().getResource("").getPath()).getParent(), "version").getPath(); @@ -116,6 +117,10 @@ public class InMemoryDefaultTestModule extends AbstractModule { properties.setProperty(Configuration.SHARED_RESOURCES_DIR.getKey(), sharedResourcesDir); } + if (!properties.containsKey(Configuration.RESOURCES_DIR.getKey())) { + properties.setProperty(Configuration.RESOURCES_DIR.getKey(), resourcesDir); + } + try { install(Modules.override(new BeanDefinitionsCachingTestControllerModule(properties)).with(new AbstractModule() { @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java index 2388c11..aafe557 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java @@ -17,15 +17,11 @@ */ package org.apache.ambari.server.orm.dao; -import static org.easymock.EasyMock.createMockBuilder; - import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; -import junit.framework.Assert; - import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.orm.GuiceJpaInitializer; @@ -40,9 +36,12 @@ import org.apache.ambari.server.orm.entities.ResourceTypeEntity; import org.apache.ambari.server.orm.entities.ServiceConfigEntity; import org.apache.ambari.server.orm.entities.StackEntity; import org.apache.ambari.server.security.authorization.ResourceType; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.cluster.ClusterImpl; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -393,7 +392,7 @@ public class ServiceConfigDAOTest { serviceConfigs = serviceConfigDAO.getLatestServiceConfigs(clusterId, HDP_02); Assert.assertEquals(2, serviceConfigs.size()); } - + @Test public void testConfiguration() throws Exception{ initClusterEntities(); @@ -401,17 +400,17 @@ public class ServiceConfigDAOTest { Assert.assertTrue(!clusterEntity.getClusterConfigEntities().isEmpty()); Assert.assertTrue(!clusterEntity.getConfigMappingEntities().isEmpty()); - + Assert.assertEquals(5, clusterEntity.getClusterConfigEntities().size()); Assert.assertEquals(3, clusterEntity.getConfigMappingEntities().size()); } - + @Test public void testGetClusterConfigMappingByStack() throws Exception{ initClusterEntities(); - + ClusterEntity clusterEntity = clusterDAO.findByName("c1"); - + List<ClusterConfigMappingEntity> clusterConfigMappingEntities = clusterDAO.getClusterConfigMappingsByStack(clusterEntity.getClusterId(), HDP_01); Assert.assertEquals(2, clusterConfigMappingEntities .size()); @@ -420,14 +419,14 @@ public class ServiceConfigDAOTest { Assert.assertEquals("version1", tag1); String type1 = e1.getType(); Assert.assertEquals("oozie-site", type1); - + ClusterConfigMappingEntity e2 = clusterConfigMappingEntities.get(1); String tag2 = e2.getTag(); Assert.assertEquals("version2", tag2); String type2 = e2.getType(); Assert.assertEquals("oozie-site", type2); } - + /** * Test the get latest configuration query against clusterconfig table with configuration groups inserted * */ @@ -435,9 +434,9 @@ public class ServiceConfigDAOTest { public void testGetClusterConfigMappingByStackCG() throws Exception{ initClusterEntitiesWithConfigGroups(); ClusterEntity clusterEntity = clusterDAO.findByName("c1"); - + List<ConfigGroupEntity> configGroupEntities = configGroupDAO.findAllByTag("OOZIE"); - + Assert.assertNotNull(configGroupEntities); ConfigGroupEntity configGroupEntity = configGroupEntities.get(0); Assert.assertNotNull(configGroupEntity); @@ -447,7 +446,7 @@ public class ServiceConfigDAOTest { Assert.assertEquals("oozie_server", configGroupEntity.getGroupName()); Assert.assertEquals("OOZIE", configGroupEntity.getTag()); Assert.assertEquals("oozie server", configGroupEntity.getDescription()); - + List<ClusterConfigMappingEntity> clusterConfigMappingEntities = clusterDAO.getClusterConfigMappingsByStack(clusterEntity.getClusterId(), HDP_01); Assert.assertEquals(2, clusterConfigMappingEntities .size()); @@ -456,97 +455,95 @@ public class ServiceConfigDAOTest { Assert.assertEquals("version1", tag1); String type1 = e1.getType(); Assert.assertEquals("oozie-site", type1); - + ClusterConfigMappingEntity e2 = clusterConfigMappingEntities.get(1); String tag2 = e2.getTag(); Assert.assertEquals("version2", tag2); String type2 = e2.getType(); Assert.assertEquals("oozie-site", type2); } - + /** - * Test + * Test * - * When the last configuration of a given configuration type to be stored into the clusterconfig table is + * When the last configuration of a given configuration type to be stored into the clusterconfig table is * for a configuration group, there is no corresponding entry generated in the clusterconfigmapping. * * Therefore, the getlatestconfiguration query should skip configuration groups stored in the clusterconfig table. * - * Test to determine the latest configuration of a given type whose version_tag + * Test to determine the latest configuration of a given type whose version_tag * exists in the clusterconfigmapping table. * * */ @Test - public void testGetLatestClusterConfigMappingByStack() throws Exception{ - ClusterImpl cluster = - createMockBuilder(ClusterImpl.class). - addMockedMethod("getSessionManager"). - addMockedMethod("getClusterName"). - addMockedMethod("getSessionAttributes"). - createMock(); - + public void testGetLatestClusterConfigMappingByStack() throws Exception { + Clusters clusters = injector.getInstance(Clusters.class); + clusters.addCluster("c1", HDP_01); + + Cluster cluster = clusters.getCluster("c1"); + initClusterEntities(); - ClusterEntity clusterEntity = clusterDAO.findByName("c1"); - List<ClusterConfigMappingEntity> clusterConfigMappingEntities = clusterDAO.getClusterConfigMappingsByStack(clusterEntity.getClusterId(), HDP_01); - Collection<ClusterConfigMappingEntity> latestMapingEntities = cluster.getLatestConfigMapping(clusterConfigMappingEntities); + + Collection<ClusterConfigMappingEntity> latestMapingEntities = ((ClusterImpl) cluster).getLatestConfigMappingsForStack( + cluster.getClusterId(), HDP_01); + Assert.assertEquals(1, latestMapingEntities.size()); for(ClusterConfigMappingEntity e: latestMapingEntities){ Assert.assertEquals("version2", e.getTag()); Assert.assertEquals("oozie-site", e.getType()); } } - + /** - * Test + * Test * - * When the last configuration of a given configuration type to be stored into the clusterconfig table is + * When the last configuration of a given configuration type to be stored into the clusterconfig table is * for a configuration group, there is no corresponding entry generated in the clusterconfigmapping. * * Therefore, the getlatestconfiguration query should skip configuration groups stored in the clusterconfig table. * - * Test to determine the latest configuration of a given type whose version_tag + * Test to determine the latest configuration of a given type whose version_tag * exists in the clusterconfigmapping table. * * */ @Test public void testGetLatestClusterConfigMappingByStackCG() throws Exception{ - ClusterImpl cluster = - createMockBuilder(ClusterImpl.class). - addMockedMethod("getSessionManager"). - addMockedMethod("getClusterName"). - addMockedMethod("getSessionAttributes"). - createMock(); - + Clusters clusters = injector.getInstance(Clusters.class); + clusters.addCluster("c1", HDP_01); + + Cluster cluster = clusters.getCluster("c1"); + initClusterEntitiesWithConfigGroups(); - ClusterEntity clusterEntity = clusterDAO.findByName("c1"); - List<ClusterConfigMappingEntity> clusterConfigMappingEntities = clusterDAO.getClusterConfigMappingsByStack(clusterEntity.getClusterId(), HDP_01); - Collection<ClusterConfigMappingEntity> latestMapingEntities = cluster.getLatestConfigMapping(clusterConfigMappingEntities); + + Collection<ClusterConfigMappingEntity> latestMapingEntities = ((ClusterImpl) cluster).getLatestConfigMappingsForStack( + cluster.getClusterId(), HDP_01); + Assert.assertEquals(1, latestMapingEntities.size()); for(ClusterConfigMappingEntity e: latestMapingEntities){ Assert.assertEquals("version2", e.getTag()); Assert.assertEquals("oozie-site", e.getType()); } } - + private void initClusterEntities() throws Exception{ String userName = "admin"; - + ServiceConfigEntity oozieServiceConfigEntity = createServiceConfig("OOZIE", userName, 1L, 1L, System.currentTimeMillis(), null); ClusterEntity clusterEntity = oozieServiceConfigEntity.getClusterEntity(); - + Long clusterId = clusterEntity.getClusterId(); - + if(null == clusterId){ clusterId = 1L; clusterEntity.setClusterId(clusterId); clusterEntity = clusterDAO.merge(clusterEntity); } - + StackEntity stackEntityHDP01 = stackDAO.find(HDP_01.getStackName(),HDP_01.getStackVersion()); StackEntity stackEntityHDP02 = stackDAO.find(HDP_02.getStackName(),HDP_02.getStackVersion()); - + String oozieSite = "oozie-site"; - + for (int i = 1; i < 6; i++){ ClusterConfigEntity entity = new ClusterConfigEntity(); entity.setClusterEntity(clusterEntity); @@ -555,22 +552,23 @@ public class ServiceConfigDAOTest { entity.setVersion(Long.valueOf(i)); entity.setTag("version"+i); entity.setTimestamp(new Date().getTime()); - if(i < 4) + if(i < 4) { entity.setStack(stackEntityHDP01); - else + } else { entity.setStack(stackEntityHDP02); + } entity.setData(""); clusterDAO.createConfig(entity); clusterEntity.getClusterConfigEntities().add(entity); clusterDAO.merge(clusterEntity); } - + Collection<ClusterConfigMappingEntity> entities = clusterEntity.getConfigMappingEntities(); if(null == entities){ entities = new ArrayList<ClusterConfigMappingEntity>(); clusterEntity.setConfigMappingEntities(entities); - } - + } + ClusterConfigMappingEntity e1 = new ClusterConfigMappingEntity(); e1.setClusterEntity(clusterEntity); e1.setClusterId(clusterEntity.getClusterId()); @@ -581,7 +579,7 @@ public class ServiceConfigDAOTest { e1.setTag("version1"); entities.add(e1); clusterDAO.merge(clusterEntity); - + ClusterConfigMappingEntity e2 = new ClusterConfigMappingEntity(); e2.setClusterEntity(clusterEntity); e2.setClusterId(clusterEntity.getClusterId()); @@ -592,7 +590,7 @@ public class ServiceConfigDAOTest { e2.setTag("version2"); entities.add(e2); clusterDAO.merge(clusterEntity); - + ClusterConfigMappingEntity e3 = new ClusterConfigMappingEntity(); e3.setClusterEntity(clusterEntity); e3.setClusterId(clusterEntity.getClusterId()); @@ -603,25 +601,25 @@ public class ServiceConfigDAOTest { e3.setTag("version4"); entities.add(e3); clusterDAO.merge(clusterEntity); - } - + } + private void initClusterEntitiesWithConfigGroups() throws Exception{ String userName = "admin"; - + ServiceConfigEntity oozieServiceConfigEntity = createServiceConfig("OOZIE", userName, 1L, 1L, System.currentTimeMillis(), null); ClusterEntity clusterEntity = oozieServiceConfigEntity.getClusterEntity(); - + Long clusterId = clusterEntity.getClusterId(); - + if(null == clusterId){ clusterId = 1L; clusterEntity.setClusterId(clusterId); clusterEntity = clusterDAO.merge(clusterEntity); } - + StackEntity stackEntityHDP01 = stackDAO.find(HDP_01.getStackName(),HDP_01.getStackVersion()); String oozieSite = "oozie-site"; - + int count = 3; for (int i = 1; i < count; i++){ ClusterConfigEntity entity = new ClusterConfigEntity(); @@ -637,13 +635,13 @@ public class ServiceConfigDAOTest { clusterEntity.getClusterConfigEntities().add(entity); clusterDAO.merge(clusterEntity); } - + Collection<ClusterConfigMappingEntity> entities = clusterEntity.getConfigMappingEntities(); if(null == entities){ entities = new ArrayList<ClusterConfigMappingEntity>(); clusterEntity.setConfigMappingEntities(entities); - } - + } + ClusterConfigMappingEntity e1 = new ClusterConfigMappingEntity(); e1.setClusterEntity(clusterEntity); e1.setClusterId(clusterEntity.getClusterId()); @@ -654,7 +652,7 @@ public class ServiceConfigDAOTest { e1.setTag("version1"); entities.add(e1); clusterDAO.merge(clusterEntity); - + ClusterConfigMappingEntity e2 = new ClusterConfigMappingEntity(); e2.setClusterEntity(clusterEntity); e2.setClusterId(clusterEntity.getClusterId()); @@ -665,7 +663,7 @@ public class ServiceConfigDAOTest { e2.setTag("version2"); entities.add(e2); clusterDAO.merge(clusterEntity); - + ConfigGroupEntity configGroupEntity = new ConfigGroupEntity(); ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findById(ResourceType.CLUSTER.getId()); @@ -695,9 +693,9 @@ public class ServiceConfigDAOTest { List<ClusterConfigEntity> configEntities = new ArrayList<ClusterConfigEntity>(); configEntities.add(configEntity); - + configGroupDAO.create(configGroupEntity); - + if (configEntities != null && !configEntities.isEmpty()) { List<ConfigGroupConfigMappingEntity> configMappingEntities = new ArrayList<ConfigGroupConfigMappingEntity>(); @@ -719,7 +717,7 @@ public class ServiceConfigDAOTest { configMappingEntities.add(configMappingEntity); configGroupConfigMappingDAO.create(configMappingEntity); } - + configGroupEntity.setConfigGroupConfigMappingEntities(configMappingEntities); configGroupDAO.merge(configGroupEntity); } http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java index 1866b12..2840e3d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java @@ -38,6 +38,7 @@ import org.apache.ambari.server.orm.entities.PrivilegeEntity; import org.apache.ambari.server.orm.entities.UserEntity; import org.apache.ambari.server.security.authorization.AmbariLdapUtils; import org.apache.ambari.server.security.authorization.Group; +import org.apache.ambari.server.security.authorization.GroupType; import org.apache.ambari.server.security.authorization.LdapServerProperties; import org.apache.ambari.server.security.authorization.User; import org.apache.ambari.server.security.authorization.Users; @@ -1576,7 +1577,7 @@ public class AmbariLdapDataPopulatorTest { final GroupEntity ldapGroup = new GroupEntity(); ldapGroup.setGroupId(1); ldapGroup.setGroupName("ldapGroup"); - ldapGroup.setLdapGroup(true); + ldapGroup.setGroupType(GroupType.LDAP); ldapGroup.setMemberEntities(new HashSet<MemberEntity>()); final User ldapUserWithoutGroup = createLdapUserWithoutGroup(); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java index 0163024..80a3bc5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java @@ -49,8 +49,7 @@ import org.apache.ambari.server.orm.entities.HostVersionEntity; import org.apache.ambari.server.orm.entities.StackEntity; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Config; -import org.apache.ambari.server.state.ConfigImpl; +import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.RepositoryInfo; import org.apache.ambari.server.state.RepositoryVersionState; @@ -113,6 +112,9 @@ public class ComponentVersionCheckActionTest { @Inject private ServiceComponentHostFactory serviceComponentHostFactory; + @Inject + private ConfigFactory configFactory; + @Before public void setup() throws Exception { m_injector = Guice.createInjector(new InMemoryDefaultTestModule()); @@ -399,18 +401,11 @@ public class ComponentVersionCheckActionTest { properties.put("a", "a1"); properties.put("b", "b1"); - Config c1 = new ConfigImpl(cluster, "hdfs-site", properties, propertiesAttributes, m_injector); + configFactory.createNew(cluster, "hdfs-site", "version1", properties, propertiesAttributes); properties.put("c", "c1"); properties.put("d", "d1"); - Config c2 = new ConfigImpl(cluster, "core-site", properties, propertiesAttributes, m_injector); - Config c3 = new ConfigImpl(cluster, "foo-site", properties, propertiesAttributes, m_injector); - - cluster.addConfig(c1); - cluster.addConfig(c2); - cluster.addConfig(c3); - c1.persist(); - c2.persist(); - c3.persist(); + configFactory.createNew(cluster, "core-site", "version1", properties, propertiesAttributes); + configFactory.createNew(cluster, "foo-site", "version1", properties, propertiesAttributes); } }