Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ public enum ExperimentalFeature {
/**
* For code that is for multi-service
*/
MULTI_SERVICE
MULTI_SERVICE,

/**
* For code that is for upgrading Mpacks. Use this to mark code that may ultimately
* be removed.
*/
MPACK_UPGRADES
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.apache.ambari.server.state.stack.upgrade.HostOrderGrouping;
import org.apache.ambari.server.state.stack.upgrade.HostOrderItem;
import org.apache.ambari.server.state.stack.upgrade.HostOrderItem.HostOrderActionType;
import org.apache.ambari.server.state.stack.upgrade.Lifecycle;
import org.apache.ambari.server.state.stack.upgrade.UpgradeScope;
import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -1296,7 +1297,7 @@ void check(Cluster cluster, Direction direction, UpgradeType type, UpgradePack u
// verify that the upgradepack has the required grouping and set the
// action items on it
HostOrderGrouping hostOrderGrouping = null;
List<Grouping> groupings = upgradePack.getGroups(direction);
List<Grouping> groupings = upgradePack.getGroups(Lifecycle.LifecycleType.UPGRADE, direction);
for (Grouping grouping : groupings) {
if (grouping instanceof HostOrderGrouping) {
hostOrderGrouping = (HostOrderGrouping) grouping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.ambari.server.state.stack.UpgradePack.ProcessingComponent;
import org.apache.ambari.server.state.stack.upgrade.Direction;
import org.apache.ambari.server.state.stack.upgrade.Grouping;
import org.apache.ambari.server.state.stack.upgrade.Lifecycle;
import org.apache.ambari.server.state.stack.upgrade.ManualTask;
import org.apache.ambari.server.state.stack.upgrade.RestartTask;
import org.apache.ambari.server.state.stack.upgrade.ServiceCheckGrouping;
Expand Down Expand Up @@ -301,7 +302,7 @@ public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack,
List<UpgradeGroupHolder> groups = new ArrayList<>();

UpgradeGroupHolder previousGroupHolder = null;
for (Grouping group : upgradePack.getGroups(context.getDirection())) {
for (Grouping group : upgradePack.getGroups(Lifecycle.LifecycleType.UPGRADE, context.getDirection())) {

// !!! grouping is not scoped to context
if (!context.isScoped(group.scope)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package org.apache.ambari.server.state.stack;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;

import javax.xml.bind.Unmarshaller;
Expand All @@ -35,12 +37,15 @@
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlValue;

import org.apache.ambari.annotations.Experimental;
import org.apache.ambari.annotations.ExperimentalFeature;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.state.stack.upgrade.ClusterGrouping;
import org.apache.ambari.server.state.stack.upgrade.ConfigureTask;
import org.apache.ambari.server.state.stack.upgrade.CreateAndConfigureTask;
import org.apache.ambari.server.state.stack.upgrade.Direction;
import org.apache.ambari.server.state.stack.upgrade.Grouping;
import org.apache.ambari.server.state.stack.upgrade.Lifecycle;
import org.apache.ambari.server.state.stack.upgrade.ServiceCheckGrouping;
import org.apache.ambari.server.state.stack.upgrade.Task;
import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
Expand All @@ -55,8 +60,6 @@
@XmlAccessorType(XmlAccessType.FIELD)
public class UpgradePack {

private static final String ALL_VERSIONS = "*";

private static final Logger LOG = LoggerFactory.getLogger(UpgradePack.class);

/**
Expand All @@ -70,9 +73,8 @@ public class UpgradePack {
@XmlElement(name="target-stack")
private String targetStack;

@XmlElementWrapper(name="order")
@XmlElement(name="group")
private List<Grouping> groups;
@XmlElement(name="lifecycle")
public List<Lifecycle> lifecycles;

@XmlElement(name="prerequisite-checks")
private PrerequisiteChecks prerequisiteChecks;
Expand Down Expand Up @@ -152,8 +154,8 @@ public UpgradeType getType() {
*/
public List<String> getPrerequisiteChecks() {
if (prerequisiteChecks == null) {
return new ArrayList<String>();
}
return new ArrayList<>();
}
return new ArrayList<>(prerequisiteChecks.checks);
}

Expand All @@ -164,7 +166,7 @@ public List<String> getPrerequisiteChecks() {
public PrerequisiteCheckConfig getPrerequisiteCheckConfig() {
if (prerequisiteChecks == null) {
return new PrerequisiteCheckConfig();
}
}
return prerequisiteChecks.configuration;
}

Expand Down Expand Up @@ -281,8 +283,16 @@ public boolean isServiceCheckFailureAutoSkipped() {
return skipServiceCheckFailures;
}

/**
* Used to get all groups defined for an upgrade. This method is deprecated as orchestration
* will change to per-lifecycle. At the time of writing, keep this for compilation purposes.
* @return
*/
@Experimental(feature = ExperimentalFeature.MPACK_UPGRADES)
@Deprecated
public List<Grouping> getAllGroups() {
return groups;

return Collections.emptyList();
}

/**
Expand All @@ -293,19 +303,28 @@ public List<Grouping> getAllGroups() {
* the direction to return the ordered groups
* @return the list of groups
*/
public List<Grouping> getGroups(Direction direction) {
List<Grouping> list = new ArrayList<>();
public List<Grouping> getGroups(Lifecycle.LifecycleType type, Direction direction) {

// !!! lifecycles are bound to be only one per-type per-Upgrade Pack, so findFirst() is ok here
Optional<Lifecycle> optional = lifecycles.stream().filter(l -> l.type == type).findFirst();
if (!optional.isPresent()) {
return Collections.<Grouping>emptyList();
}

List<Grouping> list;
List<Grouping> groups = optional.get().groups;

if (direction.isUpgrade()) {
list = groups;
} else {
switch (type) {
switch (this.type) {
case NON_ROLLING:
list = getDowngradeGroupsForNonrolling();
list = getDowngradeGroupsForNonrolling(groups);
break;
case HOST_ORDERED:
case ROLLING:
default:
list = getDowngradeGroupsForRolling();
list = getDowngradeGroupsForRolling(groups);
break;
}
}
Expand Down Expand Up @@ -369,7 +388,7 @@ public boolean canBeApplied(String targetVersion){
* </ol>
* @return the list of groups, reversed appropriately for a downgrade.
*/
private List<Grouping> getDowngradeGroupsForRolling() {
private List<Grouping> getDowngradeGroupsForRolling(List<Grouping> groups) {
List<Grouping> reverse = new ArrayList<>();

// !!! Testing exposed groups.size() == 1 issue. Normally there's no precedent for
Expand Down Expand Up @@ -405,7 +424,7 @@ private List<Grouping> getDowngradeGroupsForRolling() {
return reverse;
}

private List<Grouping> getDowngradeGroupsForNonrolling() {
private List<Grouping> getDowngradeGroupsForNonrolling(List<Grouping> groups) {
List<Grouping> list = new ArrayList<>();
for (Grouping g : groups) {
list.add(g);
Expand Down Expand Up @@ -477,8 +496,10 @@ private void initializeProcessingComponentMappings() {
* @return {@code true} if the upgrade targets any version or stack. Both
* {@link #target} and {@link #targetStack} must equal "*"
*/
@Deprecated
@Experimental(feature=ExperimentalFeature.MPACK_UPGRADES)
public boolean isAllTarget() {
return ALL_VERSIONS.equals(target) && ALL_VERSIONS.equals(targetStack);
return false;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ambari.server.state.stack.upgrade;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlRootElement;

/**
* A lifecycle is used to delineate specific portions of an upgrade. Orchestration
* will occur based on the lifecycle phases in order they are declared in {@link LifecycleType},
* namely:
*
* <ol>
* <li>INSTALL</li>
* <li>QUIET</li>
* <li>SNAPSHOT</li>
* <li>PREPARE</li>
* <li>STOP</li>
* <li>UPGRADE</li>
* <li>START</li>
* <li>FINALIZE</li>
* </ol>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Lifecycle {

@XmlAttribute
public LifecycleType type;

@XmlElementWrapper(name="order")
@XmlElement(name="group")
public List<Grouping> groups;

/**
* Identifies the lifecycle types
*/
@XmlEnum
public enum LifecycleType {

/**
* Work required that can be classified as installation. Normally installation of
* bits occurs outside the scope of upgrade orchestration.
*/
@XmlEnumValue("install")
INSTALL(1.0f),

/**
* Work to stop and wait on, for example, queues or topologies.
*/
@XmlEnumValue("quiet")
QUIET(2.0f),

/**
* Work required to snapshot or other backup.
*/
@XmlEnumValue("snapshot")
SNAPSHOT(3.0f),

/**
* Work required to prepare to upgrade.
*/
@XmlEnumValue("prepare")
PREPARE(4.0f),

/**
* Work required to stop a service.
*/
@XmlEnumValue("stop")
STOP(5.0f),

/**
* For a Rolling upgrade, work required to restart and upgrade the service.
*/
@XmlEnumValue("upgrade")
UPGRADE(6.0f),

/**
* Work required to start a service.
*/
@XmlEnumValue("start")
START(7.0f),

/**
* Work required to finalize. Will not happen until the end of the upgrade.
*/
@XmlEnumValue("finalize")
FINALIZE(8.0f);

private float m_order;

private LifecycleType(float order) {
m_order = order;
}


/**
* Returns the ordered collection of lifecycle types. This is prefered over {@link #values()}
* to preserve ordering when adding new values.
*/
public static Collection<LifecycleType> ordered() {
return Stream.of(LifecycleType.values()).sorted((l1, l2) ->
Float.compare(l1.m_order, l2.m_order)).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to the dark side ... :)

}
}

}
Loading