ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adorosz...@apache.org
Subject [29/50] [abbrv] ambari git commit: AMBARI-22325. Simplify lambdas (adoroszlai)
Date Wed, 06 Dec 2017 10:10:27 GMT
AMBARI-22325. Simplify lambdas (adoroszlai)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4b599a6b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4b599a6b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4b599a6b

Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2
Commit: 4b599a6ba5f96658ad027e2acf6885335ce66346
Parents: b0f6c6f
Author: Attila Doroszlai <adoroszlai@hortonworks.com>
Authored: Mon Nov 13 09:41:16 2017 +0100
Committer: Doroszlai, Attila <adoroszlai@hortonworks.com>
Committed: Tue Dec 5 23:55:56 2017 +0100

----------------------------------------------------------------------
 .../controller/DeleteIdentityHandler.java       |  2 +-
 .../server/controller/StackV2Factory.java       |  2 +-
 .../utilities/RemovableIdentities.java          |  4 +--
 .../controller/utilities/UsedIdentities.java    |  2 +-
 .../ambari/server/topology/BlueprintImplV2.java | 35 ++++++++++----------
 .../server/topology/BlueprintV2Factory.java     |  2 +-
 .../ambari/server/topology/HostGroupV2Impl.java |  6 ++--
 .../ambari/server/topology/ServiceGroup.java    |  3 +-
 .../apache/ambari/server/topology/Setting.java  |  2 +-
 9 files changed, 30 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/controller/DeleteIdentityHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/DeleteIdentityHandler.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/DeleteIdentityHandler.java
index cc84ce2..84c324e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/DeleteIdentityHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/DeleteIdentityHandler.java
@@ -233,7 +233,7 @@ class DeleteIdentityHandler {
     }
 
     private Set<String> serviceNames() {
-      return componentFilter().stream().map(component -> component.getServiceName()).collect(toSet());
+      return componentFilter().stream().map(Component::getServiceName).collect(toSet());
     }
 
     private List<Component> componentFilter() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
index 784b368..0735171 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
@@ -85,7 +85,7 @@ public class StackV2Factory {
     List<Map.Entry<String, String>> componentServices = stackData.serviceComponents.entrySet().stream().
       flatMap(e -> e.getValue().stream().map( v -> new SimpleImmutableEntry<>(e.getKey(),
v))).
       collect(Collectors.toList());
-    componentServices.stream().forEach( componentService -> {
+    componentServices.forEach( componentService -> {
       try {
         ComponentInfo componentInfo = controller.getAmbariMetaInfo().getComponent(stackData.stackName,
           stackData.stackVersion, componentService.getKey(), componentService.getValue());

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/RemovableIdentities.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/RemovableIdentities.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/RemovableIdentities.java
index cd23e83..ef9518d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/RemovableIdentities.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/RemovableIdentities.java
@@ -101,7 +101,7 @@ public class RemovableIdentities {
   }
 
   private static ServiceExclude excludeService(String excludedServiceName) {
-    return serviceName -> excludedServiceName.equals(serviceName);
+    return excludedServiceName::equals;
   }
 
   private static ComponentExclude excludeComponent(String excludedServiceName, String excludedComponentName,
String excludedHostName) {
@@ -116,7 +116,7 @@ public class RemovableIdentities {
 
   private static List<KerberosIdentityDescriptor> componentIdentities(List<String>
componentNames, KerberosServiceDescriptor serviceDescriptor) throws AmbariException {
     return componentNames.stream()
-      .map(componentName -> serviceDescriptor.getComponent(componentName))
+      .map(serviceDescriptor::getComponent)
       .filter(Objects::nonNull)
       .flatMap(componentDescriptor -> componentDescriptor.getIdentitiesSkipReferences().stream())
       .collect(toList());

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/UsedIdentities.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/UsedIdentities.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/UsedIdentities.java
index 2f0974e..2df713f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/UsedIdentities.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/UsedIdentities.java
@@ -86,7 +86,7 @@ public class UsedIdentities {
    * @return true if there is an identity in the used list with the same keytab or principal
name than the given identity
    */
   public boolean contains(KerberosIdentityDescriptor identity) {
-    return used.stream().anyMatch(each -> identity.isShared(each));
+    return used.stream().anyMatch(identity::isShared);
   }
 
   public interface ServiceExclude {

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
index d889fc2..ad98adc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.function.Function;
 
 import javax.annotation.Nonnull;
 
@@ -68,7 +69,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
 
   public void setStacks(Map<StackId, StackV2> stacks) {
     this.stacks = stacks;
-    getAllServices().stream().forEach(s -> s.setStackFromBlueprint(this));
+    getAllServices().forEach(s -> s.setStackFromBlueprint(this));
   }
 
   @JsonProperty("Blueprints")
@@ -106,14 +107,14 @@ public class BlueprintImplV2 implements BlueprintV2 {
 
   @JsonProperty("service_groups")
   public void setServiceGroups(Collection<ServiceGroup> serviceGroups) {
-    this.serviceGroups = serviceGroups.stream().collect(toMap( sg -> sg.getName(), sg
-> sg ));
+    this.serviceGroups = serviceGroups.stream().collect(toMap(ServiceGroup::getName, Function.identity()));
   }
 
   @JsonProperty("host_groups")
   public void setHostGroups(Collection<HostGroupV2Impl> hostGroups) {
     this.hostGroupMap = hostGroups.stream().collect(toMap(
-      hg -> hg.getName(),
-      hg -> hg
+      HostGroupV2Impl::getName,
+      Function.identity()
     ));
   }
 
@@ -153,7 +154,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
   @Override
   @JsonIgnore
   public Collection<String> getStackIds() {
-    return repositoryVersions.stream().map(rv -> rv.getStackId()).collect(toList());
+    return repositoryVersions.stream().map(RepositoryVersion::getStackId).collect(toList());
   }
 
   @Override
@@ -209,7 +210,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
   @Override
   @JsonIgnore
   public Collection<String> getAllServiceTypes() {
-    return getServiceGroups().stream().flatMap(sg -> sg.getServices().stream()).map(s
-> s.getType()).collect(toSet());
+    return getServiceGroups().stream().flatMap(sg -> sg.getServices().stream()).map(Service::getType).collect(toSet());
   }
 
   @Override
@@ -256,9 +257,9 @@ public class BlueprintImplV2 implements BlueprintV2 {
   public Configuration getConfiguration() {
     if (null == configuration) {
       configuration = new Configuration(new HashMap<>(), new HashMap<>());
-      getServiceGroups().stream().forEach( sg -> addChildConfiguration(configuration,
sg.getConfiguration()) );
-      getHostGroups().values().stream().forEach(
-        hg -> hg.getComponents().stream().forEach(
+      getServiceGroups().forEach( sg -> addChildConfiguration(configuration, sg.getConfiguration())
);
+      getHostGroups().values().forEach(
+        hg -> hg.getComponents().forEach(
           c -> addChildConfiguration(configuration, c.getConfiguration())));
     }
     return configuration;
@@ -285,13 +286,13 @@ public class BlueprintImplV2 implements BlueprintV2 {
   @Override
   @JsonIgnore
   public Collection<String> getAllServiceNames() {
-    return getAllServices().stream().map(s -> s.getName()).collect(toList());
+    return getAllServices().stream().map(Service::getName).collect(toList());
   }
 
   @Nonnull
   @Override
   public Collection<String> getComponentNames(ServiceId serviceId) {
-    return getComponents(serviceId).stream().map(c -> c.getName()).collect(toList());
+    return getComponents(serviceId).stream().map(ComponentV2::getName).collect(toList());
   }
 
   @Override
@@ -355,7 +356,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
       return true;
     }
     final Set<String> serviceNames =
-      getAllServices().stream().map(s -> s.getName()).collect(toSet());
+      getAllServices().stream().map(Service::getName).collect(toSet());
     return getStacks().stream().anyMatch(
       stack -> {
         String service = stack.getServiceForConfigType(configType);
@@ -367,7 +368,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
   public void postDeserialization() {
     // Maintain a ServiceId -> Service map
     this.services = getAllServiceIds().stream().collect(toMap(
-      serviceId -> serviceId,
+      Function.identity(),
       serviceId -> {
         ServiceGroup sg = getServiceGroup(serviceId.getServiceGroup());
         Service service = null != sg ? sg.getServiceByName(serviceId.getName()) : null;
@@ -379,11 +380,11 @@ public class BlueprintImplV2 implements BlueprintV2 {
     ));
 
     // Set Service -> ServiceGroup references and Service -> Service dependencies
-    getAllServices().stream().forEach( s -> {
+    getAllServices().forEach( s -> {
       s.setServiceGroup(serviceGroups.get(s.getServiceGroupId()));
       Map<ServiceId, Service> dependencies = s.getDependentServiceIds().stream().collect(toMap(
-        serviceId -> serviceId,
-        serviceId -> getService(serviceId)
+        Function.identity(),
+        this::getService
       ));
       s.setDependencyMap(dependencies);
     });
@@ -392,7 +393,7 @@ public class BlueprintImplV2 implements BlueprintV2 {
     // Set HostGroup -> Services and Component -> Service references
     for (HostGroupV2Impl hg: hostGroupMap.values()) {
       hg.setServiceMap(hg.getServiceIds().stream().collect(toMap(
-        serviceId -> serviceId,
+        Function.identity(),
         serviceId -> this.services.get(serviceId)
       )));
       for (ComponentV2 comp: hg.getComponents()) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
index 7ad5365..4f22aea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
@@ -104,7 +104,7 @@ public class BlueprintV2Factory {
     blueprintV2.postDeserialization();
     blueprintV2.setStacks(
       blueprintV2.getStackIds().stream().collect(Collectors.toMap(
-        stackId -> new StackId(stackId),
+        StackId::new,
         stackId -> parseStack(new StackId(stackId))
       ))
     );

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
index 8834a37..dd7a316 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
@@ -128,7 +128,7 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
   @Override
   @JsonIgnore
   public Collection<String> getServiceNames() {
-    return serviceMap.values().stream().map(s -> s.getName()).collect(Collectors.toList());
+    return serviceMap.values().stream().map(Service::getName).collect(Collectors.toList());
   }
 
   @JsonIgnore
@@ -159,8 +159,8 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
 
   public void setComponents(List<ComponentV2> components) {
     this.components = components;
-    this.containsMasterComponent = components.stream().anyMatch(c -> c.isMasterComponent());
-    this.serviceIds = components.stream().map(c -> c.getServiceId()).collect(Collectors.toSet());
+    this.containsMasterComponent = components.stream().anyMatch(ComponentV2::isMasterComponent);
+    this.serviceIds = components.stream().map(ComponentV2::getServiceId).collect(Collectors.toSet());
   }
 
   @JsonIgnore

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
index 7f38b2c..a5ba2d4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
@@ -23,6 +23,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import com.google.common.collect.ListMultimap;
@@ -76,7 +77,7 @@ public class ServiceGroup {
 
   public void setServices(Collection<Service> services) {
     services.forEach(s -> s.setServiceGroup(this));
-    this.servicesByName = services.stream().collect(Collectors.toMap(Service::getName, s
-> s));
+    this.servicesByName = services.stream().collect(Collectors.toMap(Service::getName, Function.identity()));
     this.servicesByType = Multimaps.index(services, Service::getType);
     services.forEach(s -> s.setServiceGroup(this));
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b599a6b/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java
index 34542e1..496d571 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/Setting.java
@@ -108,7 +108,7 @@ public class Setting {
     List<String> values = getSettingValue(settingCategory).stream().
       flatMap(sv -> sv.entrySet().stream()).
       filter(entry -> Objects.equals(entry.getKey(), propertyName)).
-      map(entry -> entry.getValue()).
+      map(Map.Entry::getValue).
       collect(Collectors.toList());
     Preconditions.checkState(values.size() < 2, "Ambigous settings (%s) for category %s,
property %s",
       values.size(), settingCategory, settingCategory);


Mime
View raw message