|
|
@@ -22,6 +22,8 @@ import java.util.List;
|
|
|
import java.util.TreeMap;
|
|
|
import java.util.concurrent.ConcurrentMap;
|
|
|
|
|
|
+import org.apache.ambari.annotations.Experimental;
|
|
|
+import org.apache.ambari.annotations.ExperimentalFeature;
|
|
|
import org.apache.ambari.server.AmbariException;
|
|
|
import org.apache.ambari.server.actionmanager.HostRoleCommand;
|
|
|
import org.apache.ambari.server.actionmanager.HostRoleStatus;
|
|
|
@@ -29,10 +31,10 @@ import org.apache.ambari.server.agent.CommandReport;
|
|
|
import org.apache.ambari.server.api.services.AmbariMetaInfo;
|
|
|
import org.apache.ambari.server.orm.dao.ArtifactDAO;
|
|
|
import org.apache.ambari.server.orm.entities.ArtifactEntity;
|
|
|
-import org.apache.ambari.server.serveraction.AbstractServerAction;
|
|
|
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.UpgradeContext;
|
|
|
import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
|
|
|
import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
|
|
|
import org.apache.ambari.server.state.kerberos.KerberosDescriptorUpdateHelper;
|
|
|
@@ -48,34 +50,9 @@ import com.google.inject.Inject;
|
|
|
*
|
|
|
* @see org.apache.ambari.server.state.kerberos.KerberosDescriptorUpdateHelper
|
|
|
*/
|
|
|
-public class UpgradeUserKerberosDescriptor extends AbstractServerAction {
|
|
|
+public class UpgradeUserKerberosDescriptor extends AbstractUpgradeServerAction {
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(UpgradeUserKerberosDescriptor.class);
|
|
|
|
|
|
- /**
|
|
|
- * The upgrade direction.
|
|
|
- *
|
|
|
- * @see Direction
|
|
|
- */
|
|
|
- private static final String UPGRADE_DIRECTION_KEY = "upgrade_direction";
|
|
|
-
|
|
|
- /**
|
|
|
- * The original "current" stack of the cluster before the upgrade started.
|
|
|
- * This is the same regardless of whether the current direction is
|
|
|
- * {@link Direction#UPGRADE} or {@link Direction#DOWNGRADE}.
|
|
|
- *
|
|
|
- * @see Direction
|
|
|
- */
|
|
|
- private static final String ORIGINAL_STACK_KEY = "original_stack";
|
|
|
-
|
|
|
- /**
|
|
|
- * The target upgrade stack before the upgrade started. This is the same
|
|
|
- * regardless of whether the current direction is {@link Direction#UPGRADE} or
|
|
|
- * {@link Direction#DOWNGRADE}.
|
|
|
- *
|
|
|
- * @see Direction
|
|
|
- */
|
|
|
- private static final String TARGET_STACK_KEY = "target_stack";
|
|
|
-
|
|
|
private final static String KERBEROS_DESCRIPTOR_NAME = "kerberos_descriptor";
|
|
|
private final static String KERBEROS_DESCRIPTOR_BACKUP_NAME = "kerberos_descriptor_backup";
|
|
|
|
|
|
@@ -108,70 +85,73 @@ public class UpgradeUserKerberosDescriptor extends AbstractServerAction {
|
|
|
List<String> messages = new ArrayList<>();
|
|
|
List<String> errorMessages = new ArrayList<>();
|
|
|
|
|
|
- if (cluster != null) {
|
|
|
- logMessage(messages, "Obtaining the user-defined Kerberos descriptor");
|
|
|
+ UpgradeContext upgradeContext = getUpgradeContext(cluster);
|
|
|
|
|
|
- TreeMap<String, String> foreignKeys = new TreeMap<>();
|
|
|
- foreignKeys.put("cluster", String.valueOf(cluster.getClusterId()));
|
|
|
+ logMessage(messages, "Obtaining the user-defined Kerberos descriptor");
|
|
|
|
|
|
- ArtifactEntity entity = artifactDAO.findByNameAndForeignKeys("kerberos_descriptor", foreignKeys);
|
|
|
- KerberosDescriptor userDescriptor = (entity == null) ? null : kerberosDescriptorFactory.createInstance(entity.getArtifactData());
|
|
|
+ TreeMap<String, String> foreignKeys = new TreeMap<>();
|
|
|
+ foreignKeys.put("cluster", String.valueOf(cluster.getClusterId()));
|
|
|
|
|
|
- if (userDescriptor != null) {
|
|
|
- StackId originalStackId = getStackIdFromCommandParams(ORIGINAL_STACK_KEY);
|
|
|
- StackId targetStackId = getStackIdFromCommandParams(TARGET_STACK_KEY);
|
|
|
+ ArtifactEntity entity = artifactDAO.findByNameAndForeignKeys("kerberos_descriptor", foreignKeys);
|
|
|
+ KerberosDescriptor userDescriptor = (entity == null) ? null : kerberosDescriptorFactory.createInstance(entity.getArtifactData());
|
|
|
|
|
|
- if (isDowngrade()) {
|
|
|
- restoreDescriptor(foreignKeys, messages, errorMessages);
|
|
|
- } else {
|
|
|
- backupDescriptor(foreignKeys, messages, errorMessages);
|
|
|
+ if (userDescriptor != null) {
|
|
|
+
|
|
|
+ @Experimental(
|
|
|
+ feature = ExperimentalFeature.PATCH_UPGRADES,
|
|
|
+ comment = "This needs to be correctly done per-service")
|
|
|
+
|
|
|
+ StackId originalStackId = cluster.getCurrentStackVersion();
|
|
|
+ StackId targetStackId = upgradeContext.getRepositoryVersion().getStackId();
|
|
|
+
|
|
|
+ if (upgradeContext.getDirection() == Direction.DOWNGRADE) {
|
|
|
+ restoreDescriptor(foreignKeys, messages, errorMessages);
|
|
|
+ } else {
|
|
|
+ backupDescriptor(foreignKeys, messages, errorMessages);
|
|
|
|
|
|
- KerberosDescriptor newDescriptor = null;
|
|
|
- KerberosDescriptor previousDescriptor = null;
|
|
|
+ KerberosDescriptor newDescriptor = null;
|
|
|
+ KerberosDescriptor previousDescriptor = null;
|
|
|
|
|
|
- if (targetStackId == null) {
|
|
|
- logErrorMessage(messages, errorMessages, "The new stack version information was not found.");
|
|
|
- } else {
|
|
|
- logMessage(messages, String.format("Obtaining new stack Kerberos descriptor for %s.", targetStackId.toString()));
|
|
|
- newDescriptor = ambariMetaInfo.getKerberosDescriptor(targetStackId.getStackName(), targetStackId.getStackVersion());
|
|
|
+ if (targetStackId == null) {
|
|
|
+ logErrorMessage(messages, errorMessages, "The new stack version information was not found.");
|
|
|
+ } else {
|
|
|
+ logMessage(messages, String.format("Obtaining new stack Kerberos descriptor for %s.", targetStackId.toString()));
|
|
|
+ newDescriptor = ambariMetaInfo.getKerberosDescriptor(targetStackId.getStackName(), targetStackId.getStackVersion());
|
|
|
|
|
|
- if (newDescriptor == null) {
|
|
|
- logErrorMessage(messages, errorMessages, String.format("The Kerberos descriptor for the new stack version, %s, was not found.", targetStackId.toString()));
|
|
|
- }
|
|
|
+ if (newDescriptor == null) {
|
|
|
+ logErrorMessage(messages, errorMessages, String.format("The Kerberos descriptor for the new stack version, %s, was not found.", targetStackId.toString()));
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (originalStackId == null) {
|
|
|
- logErrorMessage(messages, errorMessages, "The previous stack version information was not found.");
|
|
|
- } else {
|
|
|
- logMessage(messages, String.format("Obtaining previous stack Kerberos descriptor for %s.", originalStackId.toString()));
|
|
|
- previousDescriptor = ambariMetaInfo.getKerberosDescriptor(originalStackId.getStackName(), originalStackId.getStackVersion());
|
|
|
+ if (originalStackId == null) {
|
|
|
+ logErrorMessage(messages, errorMessages, "The previous stack version information was not found.");
|
|
|
+ } else {
|
|
|
+ logMessage(messages, String.format("Obtaining previous stack Kerberos descriptor for %s.", originalStackId.toString()));
|
|
|
+ previousDescriptor = ambariMetaInfo.getKerberosDescriptor(originalStackId.getStackName(), originalStackId.getStackVersion());
|
|
|
|
|
|
- if (newDescriptor == null) {
|
|
|
- logErrorMessage(messages, errorMessages, String.format("The Kerberos descriptor for the previous stack version, %s, was not found.", originalStackId.toString()));
|
|
|
- }
|
|
|
+ if (newDescriptor == null) {
|
|
|
+ logErrorMessage(messages, errorMessages, String.format("The Kerberos descriptor for the previous stack version, %s, was not found.", originalStackId.toString()));
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (errorMessages.isEmpty()) {
|
|
|
- logMessage(messages, "Updating the user-specified Kerberos descriptor.");
|
|
|
+ if (errorMessages.isEmpty()) {
|
|
|
+ logMessage(messages, "Updating the user-specified Kerberos descriptor.");
|
|
|
|
|
|
- KerberosDescriptor updatedDescriptor = KerberosDescriptorUpdateHelper.updateUserKerberosDescriptor(
|
|
|
- previousDescriptor,
|
|
|
- newDescriptor,
|
|
|
- userDescriptor);
|
|
|
+ KerberosDescriptor updatedDescriptor = KerberosDescriptorUpdateHelper.updateUserKerberosDescriptor(
|
|
|
+ previousDescriptor,
|
|
|
+ newDescriptor,
|
|
|
+ userDescriptor);
|
|
|
|
|
|
- logMessage(messages, "Storing updated user-specified Kerberos descriptor.");
|
|
|
+ logMessage(messages, "Storing updated user-specified Kerberos descriptor.");
|
|
|
|
|
|
- entity.setArtifactData(updatedDescriptor.toMap());
|
|
|
- artifactDAO.merge(entity);
|
|
|
+ entity.setArtifactData(updatedDescriptor.toMap());
|
|
|
+ artifactDAO.merge(entity);
|
|
|
|
|
|
- logMessage(messages, "Successfully updated the user-specified Kerberos descriptor.");
|
|
|
- }
|
|
|
+ logMessage(messages, "Successfully updated the user-specified Kerberos descriptor.");
|
|
|
}
|
|
|
- } else {
|
|
|
- logMessage(messages, "A user-specified Kerberos descriptor was not found. No updates are necessary.");
|
|
|
}
|
|
|
} else {
|
|
|
- logErrorMessage(messages, errorMessages, String.format("The cluster named %s was not found.", clusterName));
|
|
|
+ logMessage(messages, "A user-specified Kerberos descriptor was not found. No updates are necessary.");
|
|
|
}
|
|
|
|
|
|
if (!errorMessages.isEmpty()) {
|
|
|
@@ -181,24 +161,6 @@ public class UpgradeUserKerberosDescriptor extends AbstractServerAction {
|
|
|
return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", StringUtils.join(messages, "\n"), StringUtils.join(errorMessages, "\n"));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Determines if upgrade direction is {@link Direction#UPGRADE} or {@link Direction#DOWNGRADE}.
|
|
|
- *
|
|
|
- * @return {@code true} if {@link Direction#DOWNGRADE}; {@code false} if {@link Direction#UPGRADE}
|
|
|
- */
|
|
|
- private boolean isDowngrade() {
|
|
|
- return Direction.DOWNGRADE.name().equalsIgnoreCase(getCommandParameterValue(UPGRADE_DIRECTION_KEY));
|
|
|
- }
|
|
|
-
|
|
|
- private StackId getStackIdFromCommandParams(String commandParamKey) {
|
|
|
- String stackId = getCommandParameterValue(commandParamKey);
|
|
|
- if (stackId == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- return new StackId(stackId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void logMessage(List<String> messages, String message) {
|
|
|
LOG.info(message);
|
|
|
messages.add(message);
|