You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2014/05/16 18:14:45 UTC
git commit: AMBARI-5790. Add test scenario for changes in composing
packages for install.(vbrodetskyi)
Repository: ambari
Updated Branches:
refs/heads/trunk 358cb97db -> 0afeed9fc
AMBARI-5790. Add test scenario for changes in composing packages for install.(vbrodetskyi)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0afeed9f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0afeed9f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0afeed9f
Branch: refs/heads/trunk
Commit: 0afeed9fc4a7c04bf9200e90a957a67bc61a1ba3
Parents: 358cb97
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Fri May 16 19:14:25 2014 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Fri May 16 19:14:25 2014 +0300
----------------------------------------------------------------------
.../AmbariManagementControllerImpl.java | 35 ++++++----
.../ambari/server/state/ServiceOsSpecific.java | 6 +-
.../AmbariManagementControllerImplTest.java | 67 ++++++++++++++++++++
3 files changed, 94 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afeed9f/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 003d56e..9796336 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -1373,19 +1373,9 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
if (serviceInfo.getOsSpecifics().containsKey(AmbariMetaInfo.ANY_OS)) {
anyOs = serviceInfo.getOsSpecifics().get(AmbariMetaInfo.ANY_OS);
}
- ServiceOsSpecific hostOs = new ServiceOsSpecific(osFamily);
- List<ServiceOsSpecific> foundedOSSpecifics = getOSSpecificsByFamily(serviceInfo.getOsSpecifics(), osFamily);
- if (!foundedOSSpecifics.isEmpty()) {
- for (ServiceOsSpecific osSpecific : foundedOSSpecifics) {
- hostOs.addPackages(osSpecific.getPackages());
- }
- // Choose repo that is relevant for host
- ServiceOsSpecific.Repo serviceRepo = hostOs.getRepo();
- if (serviceRepo != null) {
- String serviceRepoInfo = gson.toJson(serviceRepo);
- hostParams.put(SERVICE_REPO_INFO, serviceRepoInfo);
- }
- }
+
+ ServiceOsSpecific hostOs = populateServicePackagesInfo(serviceInfo, hostParams, osFamily);
+
// Build package list that is relevant for host
List<ServiceOsSpecific.Package> packages =
new ArrayList<ServiceOsSpecific.Package>();
@@ -1418,6 +1408,25 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
}
+ protected ServiceOsSpecific populateServicePackagesInfo(ServiceInfo serviceInfo, Map<String, String> hostParams,
+ String osFamily) {
+ ServiceOsSpecific hostOs = new ServiceOsSpecific(osFamily);
+ List<ServiceOsSpecific> foundedOSSpecifics = getOSSpecificsByFamily(serviceInfo.getOsSpecifics(), osFamily);
+ if (!foundedOSSpecifics.isEmpty()) {
+ for (ServiceOsSpecific osSpecific : foundedOSSpecifics) {
+ hostOs.addPackages(osSpecific.getPackages());
+ }
+ // Choose repo that is relevant for host
+ ServiceOsSpecific.Repo serviceRepo = hostOs.getRepo();
+ if (serviceRepo != null) {
+ String serviceRepoInfo = gson.toJson(serviceRepo);
+ hostParams.put(SERVICE_REPO_INFO, serviceRepoInfo);
+ }
+ }
+
+ return hostOs;
+ }
+
private List<ServiceOsSpecific> getOSSpecificsByFamily(Map<String, ServiceOsSpecific> osSpecifics, String osFamily) {
List<ServiceOsSpecific> foundedOSSpecifics = new ArrayList<ServiceOsSpecific>();
for (Entry<String, ServiceOsSpecific> osSpecific : osSpecifics.entrySet()) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afeed9f/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceOsSpecific.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceOsSpecific.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceOsSpecific.java
index cd6f689..a143ba1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceOsSpecific.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceOsSpecific.java
@@ -125,7 +125,11 @@ public class ServiceOsSpecific {
return name;
}
- private Package() { }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Package() { }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0afeed9f/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 b412245..f267744 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
@@ -37,6 +37,8 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
import junit.framework.Assert;
import org.apache.ambari.server.AmbariException;
@@ -46,6 +48,7 @@ import org.apache.ambari.server.ParentObjectNotFoundException;
import org.apache.ambari.server.ServiceComponentHostNotFoundException;
import org.apache.ambari.server.ServiceComponentNotFoundException;
import org.apache.ambari.server.ServiceNotFoundException;
+import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
@@ -55,6 +58,8 @@ import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.ServiceOsSpecific;
+import org.apache.ambari.server.state.ServiceInfo;
import org.easymock.Capture;
import org.junit.Test;
@@ -1153,4 +1158,66 @@ public class AmbariManagementControllerImplTest {
verify(injector, clusters, cluster, response1, response2, response3, stack, metaInfo, service1, service2,
component1, component2, componentHost1, componentHost2, componentHost3);
}
+
+ @Test
+ public void testPopulateServicePackagesInfo() throws Exception {
+ Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+ Injector injector = createStrictMock(Injector.class);
+ MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);
+ Clusters clusters = createNiceMock(Clusters.class);
+
+ ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
+ Map<String, String> hostParams = new HashMap<String, String>();
+ String osFamily = "testOSFamily";
+
+ Map<String, ServiceOsSpecific> osSpecifics = new HashMap<String, ServiceOsSpecific>();
+
+ ServiceOsSpecific.Package package1 = new ServiceOsSpecific.Package();
+ package1.setName("testrpm1");
+ ServiceOsSpecific.Package package2 = new ServiceOsSpecific.Package();
+ package2.setName("testrpm2");
+ ServiceOsSpecific.Package package3 = new ServiceOsSpecific.Package();
+ package3.setName("testrpm3");
+
+ List<ServiceOsSpecific.Package> packageList1 = new ArrayList<ServiceOsSpecific.Package>();
+ packageList1.add(package1);
+ List<ServiceOsSpecific.Package> packageList2 = new ArrayList<ServiceOsSpecific.Package>();
+ packageList2.add(package2);
+ packageList2.add(package3);
+
+ ServiceOsSpecific osSpecific1 = new ServiceOsSpecific("testOSFamily");
+ osSpecific1.addPackages(packageList1);
+ ServiceOsSpecific osSpecific2 = new ServiceOsSpecific("testOSFamily1,testOSFamily,testOSFamily2");
+ osSpecific2.addPackages(packageList2);
+
+ osSpecifics.put("testOSFamily", osSpecific1);
+ osSpecifics.put("testOSFamily1,testOSFamily,testOSFamily2", osSpecific2);
+
+ expect(serviceInfo.getOsSpecifics()).andReturn(osSpecifics);
+ injector.injectMembers(capture(controllerCapture));
+ expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper).anyTimes();
+
+ replay(maintHelper, injector, clusters, serviceInfo);
+
+ AmbariManagementControllerImplTest.NestedTestClass nestedTestClass = this.new NestedTestClass(null, clusters,
+ injector);
+
+ ServiceOsSpecific serviceOsSpecific = nestedTestClass.populateServicePackagesInfo(serviceInfo, hostParams, osFamily);
+
+ assertEquals(serviceOsSpecific.getPackages().size(), 3);
+ }
+
+ private class NestedTestClass extends AmbariManagementControllerImpl {
+
+ public NestedTestClass(ActionManager actionManager, Clusters clusters, Injector injector) throws Exception {
+ super(actionManager, clusters, injector);
+ }
+
+ public ServiceOsSpecific testPopulateServicePackagesInfo(ServiceInfo serviceInfo, Map<String, String> hostParams,
+ String osFamily) {
+ return super.populateServicePackagesInfo(serviceInfo, hostParams, osFamily);
+ }
+
+ }
}