|
@@ -19,7 +19,10 @@
|
|
|
|
|
|
package org.apache.ambari.server.controller.internal;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.Map;
|
|
@@ -38,6 +41,8 @@ import org.apache.ambari.server.controller.spi.Resource.Type;
|
|
|
import org.apache.ambari.server.controller.spi.SystemException;
|
|
|
import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
|
|
|
import org.apache.ambari.server.controller.utilities.PropertyHelper;
|
|
|
+import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
|
|
|
+import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
|
|
|
|
|
|
public class StackVersionResourceProvider extends ReadOnlyResourceProvider {
|
|
|
|
|
@@ -47,6 +52,7 @@ public class StackVersionResourceProvider extends ReadOnlyResourceProvider {
|
|
|
public static final String STACK_ACTIVE_PROPERTY_ID = PropertyHelper.getPropertyId("Versions", "active");
|
|
|
public static final String STACK_CONFIG_TYPES = PropertyHelper.getPropertyId("Versions", "config_types");
|
|
|
public static final String STACK_PARENT_PROPERTY_ID = PropertyHelper.getPropertyId("Versions", "parent_stack_version");
|
|
|
+ public static final String KERBEROS_DESCRIPTOR_PROPERTY_ID = PropertyHelper.getPropertyId("Versions", "kerberos_descriptor");
|
|
|
|
|
|
private static Set<String> pkPropertyIds = new HashSet<String>(
|
|
|
Arrays.asList(new String[] { STACK_NAME_PROPERTY_ID, STACK_VERSION_PROPERTY_ID }));
|
|
@@ -104,12 +110,69 @@ public class StackVersionResourceProvider extends ReadOnlyResourceProvider {
|
|
|
setResourceProperty(resource, STACK_CONFIG_TYPES,
|
|
|
response.getConfigTypes(), requestedIds);
|
|
|
|
|
|
+ // TODO (rlevas): Convert this to an official resource
|
|
|
+ KerberosDescriptor kerberosDescriptor;
|
|
|
+ try {
|
|
|
+ kerberosDescriptor = buildKerberosDescriptor(response);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new SystemException("Failed to build composite Kerberos descriptor data", e);
|
|
|
+ }
|
|
|
+ if (kerberosDescriptor != null) {
|
|
|
+ setResourceProperty(resource, KERBEROS_DESCRIPTOR_PROPERTY_ID,
|
|
|
+ kerberosDescriptor.toMap(), requestedIds);
|
|
|
+ }
|
|
|
+
|
|
|
resources.add(resource);
|
|
|
}
|
|
|
|
|
|
return resources;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Given data from a StackVersionResponse build a complete Kerberos descriptor hierarchy.
|
|
|
+ *
|
|
|
+ * @param stackVersionResponse the StackVersionResponse instance containing the details of the
|
|
|
+ * stack and the relevant Kerberos descriptor files
|
|
|
+ * @return a KerberosDescriptor containing the complete hierarchy for the stack
|
|
|
+ * @throws IOException if the specified File is not found or not a readable
|
|
|
+ * @throws AmbariException if the specified File does not contain valid JSON-encoded Kerberos
|
|
|
+ * descriptor
|
|
|
+ */
|
|
|
+ private KerberosDescriptor buildKerberosDescriptor(StackVersionResponse stackVersionResponse)
|
|
|
+ throws IOException {
|
|
|
+ KerberosDescriptor kerberosDescriptor = null;
|
|
|
+
|
|
|
+ // Process the stack-level Kerberos descriptor file
|
|
|
+ File stackKerberosDescriptorFile = stackVersionResponse.getStackKerberosDescriptorFile();
|
|
|
+ if (stackKerberosDescriptorFile != null) {
|
|
|
+ kerberosDescriptor = KerberosDescriptor.fromFile(stackKerberosDescriptorFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Process the service-level Kerberos descriptor files
|
|
|
+ Collection<File> serviceDescriptorFiles = stackVersionResponse.getServiceKerberosDescriptorFiles();
|
|
|
+ if ((serviceDescriptorFiles != null) && !serviceDescriptorFiles.isEmpty()) {
|
|
|
+ // Make sure kerberosDescriptor is not null. This will be the case if there is no stack-level
|
|
|
+ // Kerberos descriptor file.
|
|
|
+ if (kerberosDescriptor == null) {
|
|
|
+ kerberosDescriptor = new KerberosDescriptor();
|
|
|
+ }
|
|
|
+
|
|
|
+ // For each service-level Kerberos descriptor file, parse into an array of KerberosServiceDescriptors
|
|
|
+ // and then append each to the KerberosDescriptor hierarchy.
|
|
|
+ for (File file : serviceDescriptorFiles) {
|
|
|
+ KerberosServiceDescriptor[] serviceDescriptors = KerberosServiceDescriptor.fromFile(file);
|
|
|
+
|
|
|
+ if (serviceDescriptors != null) {
|
|
|
+ for (KerberosServiceDescriptor serviceDescriptor : serviceDescriptors) {
|
|
|
+ kerberosDescriptor.putService(serviceDescriptor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return kerberosDescriptor;
|
|
|
+ }
|
|
|
+
|
|
|
private StackVersionRequest getRequest(Map<String, Object> properties) {
|
|
|
return new StackVersionRequest(
|
|
|
(String) properties.get(STACK_NAME_PROPERTY_ID),
|