|
|
@@ -122,6 +122,7 @@ import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
|
|
|
import org.apache.ambari.server.state.kerberos.VariableReplacementHelper;
|
|
|
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent;
|
|
|
import org.apache.ambari.server.utils.StageUtils;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.directory.server.kerberos.shared.keytab.Keytab;
|
|
|
@@ -268,10 +269,12 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
boolean updateConfigurations = !requestProperties.containsKey(DIRECTIVE_IGNORE_CONFIGS)
|
|
|
|| !"true".equalsIgnoreCase(requestProperties.get(DIRECTIVE_IGNORE_CONFIGS));
|
|
|
|
|
|
+ boolean forceAllHosts = (hostFilter == null) || (hostFilter.contains("*"));
|
|
|
+
|
|
|
if ("true".equalsIgnoreCase(value) || "all".equalsIgnoreCase(value)) {
|
|
|
- handler = new CreatePrincipalsAndKeytabsHandler(true, updateConfigurations, true);
|
|
|
+ handler = new CreatePrincipalsAndKeytabsHandler(KerberosServerAction.OperationType.RECREATE_ALL, updateConfigurations, forceAllHosts, true);
|
|
|
} else if ("missing".equalsIgnoreCase(value)) {
|
|
|
- handler = new CreatePrincipalsAndKeytabsHandler(false, updateConfigurations, true);
|
|
|
+ handler = new CreatePrincipalsAndKeytabsHandler(KerberosServerAction.OperationType.CREATE_MISSING, updateConfigurations, forceAllHosts, true);
|
|
|
}
|
|
|
|
|
|
if (handler != null) {
|
|
|
@@ -326,7 +329,7 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
if (serviceComponentsArray.length == 2) {
|
|
|
serviceComponentFilter.put(serviceName, ImmutableSet.copyOf(serviceComponentsArray[1].split(";")));
|
|
|
} else {
|
|
|
- serviceComponentFilter.put(serviceName, null);
|
|
|
+ serviceComponentFilter.put(serviceName, ImmutableSet.of("*"));
|
|
|
}
|
|
|
}
|
|
|
return serviceComponentFilter.build();
|
|
|
@@ -340,7 +343,7 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
RequestStageContainer requestStageContainer, Boolean manageIdentities)
|
|
|
throws AmbariException, KerberosOperationException {
|
|
|
return handle(cluster, getKerberosDetails(cluster, manageIdentities), serviceComponentFilter, hostFilter, identityFilter,
|
|
|
- hostsToForceKerberosOperations, requestStageContainer, new CreatePrincipalsAndKeytabsHandler(false, false,
|
|
|
+ hostsToForceKerberosOperations, requestStageContainer, new CreatePrincipalsAndKeytabsHandler(KerberosServerAction.OperationType.DEFAULT, false, false,
|
|
|
false));
|
|
|
}
|
|
|
|
|
|
@@ -1061,7 +1064,7 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
RequestStageContainer requestStageContainer)
|
|
|
throws KerberosOperationException, AmbariException {
|
|
|
return handleTestIdentity(cluster, getKerberosDetails(cluster, null), commandParamsStage, requestStageContainer,
|
|
|
- new CreatePrincipalsAndKeytabsHandler(false, false, false));
|
|
|
+ new CreatePrincipalsAndKeytabsHandler(KerberosServerAction.OperationType.DEFAULT, false, false, false));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1230,27 +1233,25 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
public List<ServiceComponentHost> getServiceComponentHostsToProcess(final Cluster cluster,
|
|
|
final KerberosDescriptor kerberosDescriptor,
|
|
|
final Map<String, ? extends Collection<String>> serviceComponentFilter,
|
|
|
- final Collection<String> hostFilter, Collection<String> identityFilter,
|
|
|
- final Command<Boolean, ServiceComponentHost> shouldProcessCommand)
|
|
|
+ final Collection<String> hostFilter)
|
|
|
throws AmbariException {
|
|
|
return getServiceComponentHosts(cluster, new Command<Boolean, ServiceComponentHost>() {
|
|
|
@Override
|
|
|
public Boolean invoke(ServiceComponentHost sch) throws AmbariException {
|
|
|
if (sch != null) {
|
|
|
// Check the host filter
|
|
|
- if ((hostFilter == null) || hostFilter.contains(sch.getHostName())) {
|
|
|
+ if ((hostFilter == null) || hostFilter.contains("*") || hostFilter.contains(sch.getHostName())) {
|
|
|
String serviceName = sch.getServiceName();
|
|
|
|
|
|
// Check the service filter
|
|
|
- if ((serviceComponentFilter == null) || serviceComponentFilter.containsKey(serviceName)) {
|
|
|
+ if ((serviceComponentFilter == null) || serviceComponentFilter.containsKey("*") || serviceComponentFilter.containsKey(serviceName)) {
|
|
|
KerberosServiceDescriptor serviceDescriptor = kerberosDescriptor.getService(serviceName);
|
|
|
|
|
|
if (serviceDescriptor != null) {
|
|
|
- Collection<String> componentFilter = (serviceComponentFilter == null) ? null : serviceComponentFilter.get(serviceName);
|
|
|
+ Collection<String> componentFilter = ((serviceComponentFilter == null) || serviceComponentFilter.containsKey("*")) ? null : serviceComponentFilter.get(serviceName);
|
|
|
|
|
|
- // Check the service/component filter and the shouldProcessCommand
|
|
|
- return (((componentFilter == null) || componentFilter.contains(sch.getServiceComponentName())) &&
|
|
|
- ((shouldProcessCommand == null) || shouldProcessCommand.invoke(sch)));
|
|
|
+ // Check the service/component filter
|
|
|
+ return (((componentFilter == null) || componentFilter.contains("*") || componentFilter.contains(sch.getServiceComponentName())));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1491,8 +1492,9 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
|
|
|
if (identities != null) {
|
|
|
for (KerberosIdentityDescriptor identity : identities) {
|
|
|
- // If there is no filter or the filter contains the current identity's name...
|
|
|
- if ((identityFilter == null) || identityFilter.contains(identity.getName())) {
|
|
|
+ // If there is no filter or the filter contains the current identity's path...
|
|
|
+ if ((identityFilter == null) || identityFilter.contains(identity.getPath())) {
|
|
|
+
|
|
|
KerberosPrincipalDescriptor principalDescriptor = identity.getPrincipalDescriptor();
|
|
|
String principal = null;
|
|
|
String principalType = null;
|
|
|
@@ -2030,10 +2032,7 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
cluster,
|
|
|
kerberosDescriptor,
|
|
|
serviceComponentFilter,
|
|
|
- hostFilter,
|
|
|
- identityFilter,
|
|
|
- arg -> true);
|
|
|
-
|
|
|
+ hostFilter);
|
|
|
|
|
|
// While iterating over all the ServiceComponentHosts find hosts that have KERBEROS_CLIENT
|
|
|
// components in the INSTALLED state and add them to the hostsWithValidKerberosClient Set.
|
|
|
@@ -3378,12 +3377,11 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
requestStageContainer.addStages(roleGraph.getStages());
|
|
|
}
|
|
|
|
|
|
- public void addDistributeKeytabFilesStage(Cluster cluster, List<ServiceComponentHost> serviceComponentHosts,
|
|
|
- String clusterHostInfoJson, String hostParamsJson,
|
|
|
- Map<String, String> commandParameters,
|
|
|
- RoleCommandOrder roleCommandOrder,
|
|
|
- RequestStageContainer requestStageContainer,
|
|
|
- Set<String> hostsWithValidKerberosClient)
|
|
|
+ void addDistributeKeytabFilesStage(Cluster cluster, String clusterHostInfoJson,
|
|
|
+ String hostParamsJson, Map<String, String> commandParameters,
|
|
|
+ RoleCommandOrder roleCommandOrder,
|
|
|
+ RequestStageContainer requestStageContainer,
|
|
|
+ List<String> hosts)
|
|
|
throws AmbariException {
|
|
|
|
|
|
Stage stage = createNewStage(requestStageContainer.getLastStageId(),
|
|
|
@@ -3393,20 +3391,13 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
StageUtils.getGson().toJson(commandParameters),
|
|
|
hostParamsJson);
|
|
|
|
|
|
- Collection<ServiceComponentHost> filteredComponents = filterServiceComponentHostsForHosts(
|
|
|
- new ArrayList<>(serviceComponentHosts), hostsWithValidKerberosClient);
|
|
|
-
|
|
|
- if (!filteredComponents.isEmpty()) {
|
|
|
- List<String> hostsToUpdate = createUniqueHostList(filteredComponents, Collections.singleton(HostState.HEALTHY));
|
|
|
+ if (!hosts.isEmpty()) {
|
|
|
Map<String, String> requestParams = new HashMap<>();
|
|
|
- List<RequestResourceFilter> requestResourceFilters = new ArrayList<>();
|
|
|
- RequestResourceFilter reqResFilter = new RequestResourceFilter(Service.Type.KERBEROS.name(), Role.KERBEROS_CLIENT.name(), hostsToUpdate);
|
|
|
- requestResourceFilters.add(reqResFilter);
|
|
|
|
|
|
ActionExecutionContext actionExecContext = new ActionExecutionContext(
|
|
|
cluster.getClusterName(),
|
|
|
SET_KEYTAB,
|
|
|
- requestResourceFilters,
|
|
|
+ createRequestResourceFilters(hosts),
|
|
|
requestParams);
|
|
|
customCommandExecutionHelper.addExecutionCommandsToStage(actionExecContext, stage,
|
|
|
requestParams, null);
|
|
|
@@ -3422,7 +3413,12 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
/**
|
|
|
* Send a custom command to the KERBEROS_CLIENT to check if there are missing keytabs on each hosts.
|
|
|
*/
|
|
|
- public void addCheckMissingKeytabsStage(Cluster cluster, String clusterHostInfoJson, String hostParamsJson, ServiceComponentHostServerActionEvent event, Map<String, String> commandParameters, RoleCommandOrder roleCommandOrder, RequestStageContainer requestStageContainer, List<ServiceComponentHost> serviceComponentHosts) throws AmbariException {
|
|
|
+ void addCheckMissingKeytabsStage(Cluster cluster, String clusterHostInfoJson,
|
|
|
+ String hostParamsJson, Map<String, String> commandParameters,
|
|
|
+ RoleCommandOrder roleCommandOrder,
|
|
|
+ RequestStageContainer requestStageContainer,
|
|
|
+ List<String> hostsToInclude)
|
|
|
+ throws AmbariException {
|
|
|
Stage stage = createNewStage(requestStageContainer.getLastStageId(),
|
|
|
cluster,
|
|
|
requestStageContainer.getId(),
|
|
|
@@ -3430,20 +3426,13 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
StageUtils.getGson().toJson(commandParameters),
|
|
|
hostParamsJson);
|
|
|
|
|
|
- Collection<ServiceComponentHost> filteredComponents = filterServiceComponentHostsForHosts(
|
|
|
- new ArrayList<>(serviceComponentHosts), getHostsWithValidKerberosClient(cluster));
|
|
|
-
|
|
|
- if (!filteredComponents.isEmpty()) {
|
|
|
- List<String> hostsToUpdate = createUniqueHostList(filteredComponents, Collections.singleton(HostState.HEALTHY));
|
|
|
+ if (!hostsToInclude.isEmpty()) {
|
|
|
Map<String, String> requestParams = new HashMap<>();
|
|
|
- List<RequestResourceFilter> requestResourceFilters = new ArrayList<>();
|
|
|
- RequestResourceFilter reqResFilter = new RequestResourceFilter(Service.Type.KERBEROS.name(), Role.KERBEROS_CLIENT.name(), hostsToUpdate);
|
|
|
- requestResourceFilters.add(reqResFilter);
|
|
|
|
|
|
ActionExecutionContext actionExecContext = new ActionExecutionContext(
|
|
|
cluster.getClusterName(),
|
|
|
CHECK_KEYTABS,
|
|
|
- requestResourceFilters,
|
|
|
+ createRequestResourceFilters(hostsToInclude),
|
|
|
requestParams);
|
|
|
customCommandExecutionHelper.addExecutionCommandsToStage(actionExecContext, stage, requestParams, null);
|
|
|
}
|
|
|
@@ -3454,32 +3443,6 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
requestStageContainer.addStages(roleGraph.getStages());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Filter out ServiceComponentHosts that are on on hosts in the specified set of host names.
|
|
|
- * <p/>
|
|
|
- * It is expected that the supplied collection is modifiable. It will be modified inplace.
|
|
|
- *
|
|
|
- * @param serviceComponentHosts a collection of ServiceComponentHost items to test
|
|
|
- * @param hosts a set of host names indicating valid hosts
|
|
|
- * @return a collection of filtered ServiceComponentHost items
|
|
|
- */
|
|
|
- private Collection<ServiceComponentHost> filterServiceComponentHostsForHosts(Collection<ServiceComponentHost> serviceComponentHosts,
|
|
|
- Set<String> hosts) {
|
|
|
-
|
|
|
- if ((serviceComponentHosts != null) && (hosts != null)) {
|
|
|
- Iterator<ServiceComponentHost> iterator = serviceComponentHosts.iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- ServiceComponentHost sch = iterator.next();
|
|
|
-
|
|
|
- if (!hosts.contains(sch.getHostName())) {
|
|
|
- iterator.remove();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return serviceComponentHosts;
|
|
|
- }
|
|
|
-
|
|
|
void addDisableSecurityHookStage(Cluster cluster,
|
|
|
String clusterHostInfoJson,
|
|
|
String hostParamsJson,
|
|
|
@@ -3677,6 +3640,13 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
requestStageContainer.setClusterHostInfo(clusterHostInfoJson);
|
|
|
requestStageContainer.addStages(roleGraph.getStages());
|
|
|
}
|
|
|
+
|
|
|
+ private List<RequestResourceFilter> createRequestResourceFilters(List<String> hostsToInclude) {
|
|
|
+ List<RequestResourceFilter> requestResourceFilters = new ArrayList<>();
|
|
|
+ RequestResourceFilter reqResFilter = new RequestResourceFilter(Service.Type.KERBEROS.name(), Role.KERBEROS_CLIENT.name(), hostsToInclude);
|
|
|
+ requestResourceFilters.add(reqResFilter);
|
|
|
+ return requestResourceFilters;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -3746,6 +3716,8 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
roleCommandOrder, requestStageContainer);
|
|
|
|
|
|
if (kerberosDetails.manageIdentities()) {
|
|
|
+ List<String> hostsToInclude = calculateHosts(cluster, serviceComponentHosts, hostsWithValidKerberosClient, false);
|
|
|
+
|
|
|
commandParameters.put(KerberosServerAction.KDC_TYPE, kerberosDetails.getKdcType().name());
|
|
|
|
|
|
// *****************************************************************
|
|
|
@@ -3767,8 +3739,8 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
|
|
|
// *****************************************************************
|
|
|
// Create stage to distribute keytabs
|
|
|
- addDistributeKeytabFilesStage(cluster, serviceComponentHosts, clusterHostInfoJson, hostParamsJson,
|
|
|
- commandParameters, roleCommandOrder, requestStageContainer, hostsWithValidKerberosClient);
|
|
|
+ addDistributeKeytabFilesStage(cluster, clusterHostInfoJson, hostParamsJson, commandParameters,
|
|
|
+ roleCommandOrder, requestStageContainer, hostsToInclude);
|
|
|
}
|
|
|
|
|
|
// *****************************************************************
|
|
|
@@ -3885,10 +3857,11 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
*/
|
|
|
private class CreatePrincipalsAndKeytabsHandler extends Handler {
|
|
|
/**
|
|
|
- * A boolean value indicating whether to create keytabs for all principals (<code>true</code>)
|
|
|
- * or only the ones that are missing (<code>false</code>).
|
|
|
+ * The type of Kerberos operation being performed.
|
|
|
+ *
|
|
|
+ * @see org.apache.ambari.server.serveraction.kerberos.KerberosServerAction.OperationType
|
|
|
*/
|
|
|
- private boolean regenerateAllKeytabs;
|
|
|
+ private KerberosServerAction.OperationType operationType;
|
|
|
|
|
|
/**
|
|
|
* A boolean value indicating whether to update service configurations (<code>true</code>)
|
|
|
@@ -3896,6 +3869,14 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
*/
|
|
|
private boolean updateConfigurations;
|
|
|
|
|
|
+ /**
|
|
|
+ * A boolean value indicating whether to include all hosts (<code>true</code>) when setting up
|
|
|
+ * agent-side tasks or to select only the hosts found to be relevant (<code>false</code>).
|
|
|
+ * <p>
|
|
|
+ * This is useful if we do not know beforehand, which hosts need to be involved in the operation.
|
|
|
+ */
|
|
|
+ private boolean forceAllHosts;
|
|
|
+
|
|
|
/**
|
|
|
* A boolean value indicating whether to include Ambari server identity (<code>true</code>)
|
|
|
* or ignore it (<code>false</code>).
|
|
|
@@ -3906,17 +3887,20 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
* CreatePrincipalsAndKeytabsHandler constructor to set whether this instance should be used to
|
|
|
* regenerate all keytabs or just the ones that have not been distributed
|
|
|
*
|
|
|
- * @param regenerateAllKeytabs A boolean value indicating whether to create keytabs for all
|
|
|
- * principals (<code>true</code> or only the ones that are missing
|
|
|
- * (<code>false</code>)
|
|
|
- * @param updateConfigurations A boolean value indicating whether to update service configurations
|
|
|
- * (<code>true</code>) or ignore any potential configuration changes
|
|
|
- * (<code>false</code>)
|
|
|
+ * @param operationType The type of Kerberos operation being performed
|
|
|
+ * @param updateConfigurations A boolean value indicating whether to update service configurations
|
|
|
+ * (<code>true</code>) or ignore any potential configuration changes
|
|
|
+ * @param forceAllHosts A boolean value indicating whether to include all hosts (<code>true</code>)
|
|
|
+ * when setting up agent-side tasks or to select only the hosts found to be
|
|
|
+ * relevant (<code>false</code>)
|
|
|
+ * @param includeAmbariIdentity A boolean value indicating whether to include Ambari server
|
|
|
+ * identity (<code>true</code>) or ignore it (<code>false</code>)
|
|
|
*/
|
|
|
- public CreatePrincipalsAndKeytabsHandler(boolean regenerateAllKeytabs, boolean updateConfigurations,
|
|
|
- boolean includeAmbariIdentity) {
|
|
|
- this.regenerateAllKeytabs = regenerateAllKeytabs;
|
|
|
+ CreatePrincipalsAndKeytabsHandler(KerberosServerAction.OperationType operationType, boolean updateConfigurations,
|
|
|
+ boolean forceAllHosts, boolean includeAmbariIdentity) {
|
|
|
+ this.operationType = operationType;
|
|
|
this.updateConfigurations = updateConfigurations;
|
|
|
+ this.forceAllHosts = forceAllHosts;
|
|
|
this.includeAmbariIdentity = includeAmbariIdentity;
|
|
|
}
|
|
|
|
|
|
@@ -3947,6 +3931,7 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ boolean processAmbariIdentity = includeAmbariIdentity;
|
|
|
Map<String, String> commandParameters = new HashMap<>();
|
|
|
commandParameters.put(KerberosServerAction.AUTHENTICATED_USER_NAME, ambariManagementController.getAuthName());
|
|
|
commandParameters.put(KerberosServerAction.DEFAULT_REALM, kerberosDetails.getDefaultRealm());
|
|
|
@@ -3955,22 +3940,29 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
}
|
|
|
if (serviceComponentFilter != null) {
|
|
|
commandParameters.put(KerberosServerAction.SERVICE_COMPONENT_FILTER, StageUtils.getGson().toJson(serviceComponentFilter));
|
|
|
+
|
|
|
+ processAmbariIdentity = serviceComponentFilter.containsKey("AMBARI") &&
|
|
|
+ ((serviceComponentFilter.get("AMBARI") == null) || serviceComponentFilter.get("AMBARI").contains("*") || serviceComponentFilter.get("AMBARI").contains("AMBARI_SERVER"));
|
|
|
}
|
|
|
if (hostFilter != null) {
|
|
|
commandParameters.put(KerberosServerAction.HOST_FILTER, StageUtils.getGson().toJson(hostFilter));
|
|
|
+
|
|
|
+ processAmbariIdentity = hostFilter.contains("*") || hostFilter.contains(StageUtils.getHostName());
|
|
|
}
|
|
|
if (identityFilter != null) {
|
|
|
commandParameters.put(KerberosServerAction.IDENTITY_FILTER, StageUtils.getGson().toJson(identityFilter));
|
|
|
}
|
|
|
|
|
|
- commandParameters.put(KerberosServerAction.REGENERATE_ALL, (regenerateAllKeytabs) ? "true" : "false");
|
|
|
- commandParameters.put(KerberosServerAction.INCLUDE_AMBARI_IDENTITY, (includeAmbariIdentity) ? "true" : "false");
|
|
|
+ commandParameters.put(KerberosServerAction.OPERATION_TYPE, (operationType == null) ? KerberosServerAction.OperationType.DEFAULT.name() : operationType.name());
|
|
|
+ commandParameters.put(KerberosServerAction.INCLUDE_AMBARI_IDENTITY, (processAmbariIdentity) ? "true" : "false");
|
|
|
|
|
|
if (updateConfigurations) {
|
|
|
commandParameters.put(KerberosServerAction.UPDATE_CONFIGURATION_NOTE, "Updated Kerberos-related configurations");
|
|
|
commandParameters.put(KerberosServerAction.UPDATE_CONFIGURATIONS, "true");
|
|
|
}
|
|
|
|
|
|
+ List<String> hostsToInclude = calculateHosts(cluster, serviceComponentHosts, hostsWithValidKerberosClient, forceAllHosts);
|
|
|
+
|
|
|
// *****************************************************************
|
|
|
// Create stage to create principals
|
|
|
addPrepareKerberosIdentitiesStage(cluster, clusterHostInfoJson, hostParamsJson, event,
|
|
|
@@ -3979,9 +3971,9 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
if (kerberosDetails.manageIdentities()) {
|
|
|
commandParameters.put(KerberosServerAction.KDC_TYPE, kerberosDetails.getKdcType().name());
|
|
|
|
|
|
- if (!regenerateAllKeytabs) {
|
|
|
- addCheckMissingKeytabsStage(cluster, clusterHostInfoJson, hostParamsJson, event,
|
|
|
- commandParameters, roleCommandOrder, requestStageContainer, serviceComponentHosts);
|
|
|
+ if (operationType != KerberosServerAction.OperationType.RECREATE_ALL) {
|
|
|
+ addCheckMissingKeytabsStage(cluster, clusterHostInfoJson, hostParamsJson,
|
|
|
+ commandParameters, roleCommandOrder, requestStageContainer, hostsToInclude);
|
|
|
}
|
|
|
|
|
|
// *****************************************************************
|
|
|
@@ -3996,15 +3988,15 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
|
|
|
// *****************************************************************
|
|
|
// Create stage to distribute and configure keytab for Ambari server and configure JAAS
|
|
|
- if (includeAmbariIdentity && kerberosDetails.createAmbariPrincipal()) {
|
|
|
+ if (processAmbariIdentity && kerberosDetails.createAmbariPrincipal()) {
|
|
|
addConfigureAmbariIdentityStage(cluster, clusterHostInfoJson, hostParamsJson, event, commandParameters,
|
|
|
roleCommandOrder, requestStageContainer);
|
|
|
}
|
|
|
|
|
|
// *****************************************************************
|
|
|
// Create stage to distribute keytabs
|
|
|
- addDistributeKeytabFilesStage(cluster, serviceComponentHosts, clusterHostInfoJson,
|
|
|
- hostParamsJson, commandParameters, roleCommandOrder, requestStageContainer, hostsWithValidKerberosClient);
|
|
|
+ addDistributeKeytabFilesStage(cluster, clusterHostInfoJson, hostParamsJson, commandParameters,
|
|
|
+ roleCommandOrder, requestStageContainer, hostsToInclude);
|
|
|
}
|
|
|
|
|
|
if (updateConfigurations) {
|
|
|
@@ -4018,6 +4010,74 @@ public class KerberosHelperImpl implements KerberosHelper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Filter out ServiceComponentHosts that are on on hosts in the specified set of host names.
|
|
|
+ * <p/>
|
|
|
+ * It is expected that the supplied collection is modifiable. It will be modified inplace.
|
|
|
+ *
|
|
|
+ * @param serviceComponentHosts a collection of ServiceComponentHost items to test
|
|
|
+ * @param hosts a set of host names indicating valid hosts
|
|
|
+ * @return a collection of filtered ServiceComponentHost items
|
|
|
+ */
|
|
|
+ private Collection<ServiceComponentHost> filterServiceComponentHostsForHosts(Collection<ServiceComponentHost> serviceComponentHosts,
|
|
|
+ Set<String> hosts) {
|
|
|
+
|
|
|
+ if ((serviceComponentHosts != null) && (hosts != null)) {
|
|
|
+ Iterator<ServiceComponentHost> iterator = serviceComponentHosts.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ServiceComponentHost sch = iterator.next();
|
|
|
+
|
|
|
+ if (!hosts.contains(sch.getHostName())) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return serviceComponentHosts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Calculate the hosts to include when issuing agent-side commands.
|
|
|
+ * <p>
|
|
|
+ * If forcing all hosts, select only the healthy hosts in the cluster else select only the healthy
|
|
|
+ * hosts from the set of hosts specified in the collection of relevant {@link ServiceComponentHost}.
|
|
|
+ *
|
|
|
+ * @param cluster the cluster
|
|
|
+ * @param serviceComponentHosts a collction of {@link ServiceComponentHost}s that are
|
|
|
+ * relevant to the current operation
|
|
|
+ * @param hostsWithValidKerberosClient the collection of hosts know to have the Kerberos client
|
|
|
+ * component installed
|
|
|
+ * @param forceAllHosts true to process all hosts from the cluster rather than use
|
|
|
+ * the hosts parsed from the set of {@link ServiceComponentHost}s
|
|
|
+ * @return a filtered list of host names
|
|
|
+ * @throws AmbariException
|
|
|
+ */
|
|
|
+ private List<String> calculateHosts(Cluster cluster, List<ServiceComponentHost> serviceComponentHosts, Set<String> hostsWithValidKerberosClient, boolean forceAllHosts) throws AmbariException {
|
|
|
+ if(forceAllHosts) {
|
|
|
+ List<String> hosts = new ArrayList<>();
|
|
|
+ Collection<Host> clusterHosts = cluster.getHosts();
|
|
|
+ if(!CollectionUtils.isEmpty(clusterHosts)) {
|
|
|
+ for(Host host: clusterHosts) {
|
|
|
+ if(host.getState() == HostState.HEALTHY) {
|
|
|
+ hosts.add(host.getHostName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return hosts;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Collection<ServiceComponentHost> filteredComponents = filterServiceComponentHostsForHosts(
|
|
|
+ new ArrayList<>(serviceComponentHosts), hostsWithValidKerberosClient);
|
|
|
+
|
|
|
+ if (filteredComponents.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ } else {
|
|
|
+ return createUniqueHostList(filteredComponents, Collections.singleton(HostState.HEALTHY));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* DeletePrincipalsAndKeytabsHandler is an implementation of the Handler interface used to delete
|
|
|
* principals and keytabs throughout the cluster.
|