Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMBARI-23156] Remove Required Group Name and Expose Lifecycle to API #562

Merged
merged 1 commit into from
Mar 7, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class UpgradeGroupResourceProvider extends AbstractControllerResourceProv
protected static final String UPGRADE_CLUSTER_NAME = "UpgradeGroup/cluster_name";
protected static final String UPGRADE_GROUP_NAME = "UpgradeGroup/name";
protected static final String UPGRADE_GROUP_TITLE = "UpgradeGroup/title";
protected static final String UPGRADE_GROUP_LIFECYCLE = "UpgradeGroup/lifecycle";
protected static final String UPGRADE_GROUP_PROGRESS_PERCENT = "UpgradeGroup/progress_percent";
protected static final String UPGRADE_GROUP_STATUS = "UpgradeGroup/status";
protected static final String UPGRADE_GROUP_DISPLAY_STATUS = "UpgradeGroup/display_status";
Expand All @@ -68,6 +69,7 @@ public class UpgradeGroupResourceProvider extends AbstractControllerResourceProv

private static final Set<String> PK_PROPERTY_IDS = new HashSet<>(
Arrays.asList(UPGRADE_REQUEST_ID, UPGRADE_GROUP_ID));

private static final Set<String> PROPERTY_IDS = new HashSet<>();

private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<>();
Expand All @@ -90,6 +92,7 @@ public class UpgradeGroupResourceProvider extends AbstractControllerResourceProv
PROPERTY_IDS.add(UPGRADE_GROUP_TOTAL_TASKS);
PROPERTY_IDS.add(UPGRADE_GROUP_IN_PROGRESS_TASKS);
PROPERTY_IDS.add(UPGRADE_GROUP_COMPLETED_TASKS);
PROPERTY_IDS.add(UPGRADE_GROUP_LIFECYCLE);

// keys
KEY_PROPERTY_IDS.put(Resource.Type.UpgradeGroup, UPGRADE_GROUP_ID);
Expand Down Expand Up @@ -183,6 +186,7 @@ private Resource toResource(UpgradeEntity upgrade, UpgradeGroupEntity group, Set
setResourceProperty(resource, UPGRADE_GROUP_ID, group.getId(), requestedIds);
setResourceProperty(resource, UPGRADE_GROUP_NAME, group.getName(), requestedIds);
setResourceProperty(resource, UPGRADE_GROUP_TITLE, group.getTitle(), requestedIds);
setResourceProperty(resource, UPGRADE_GROUP_LIFECYCLE, group.getLifecycle(), requestedIds);

return resource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ major stack versions (e.g., HDP 2.2 -> 2.3), and then set config changes

if(!itemEntities.isEmpty()) {
UpgradeGroupEntity groupEntity = new UpgradeGroupEntity();
groupEntity.setLifecycle(group.lifecycle);
groupEntity.setName(group.name);
groupEntity.setTitle(group.title);
groupEntity.setItems(itemEntities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand All @@ -32,6 +34,8 @@
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import org.apache.ambari.server.state.stack.upgrade.LifecycleType;

/**
* Models a single upgrade group as part of an entire {@link UpgradeEntity}.
* <p/>
Expand All @@ -57,8 +61,12 @@ public class UpgradeGroupEntity {
@Column(name = "upgrade_id", nullable = false, insertable = false, updatable = false)
private Long upgradeId;

@Column(name = "lifecycle", length=255, nullable = false)
@Enumerated(value = EnumType.STRING)
private LifecycleType lifecycle;

@Basic
@Column(name = "group_name", length=255, nullable = false)
@Column(name = "group_name", length=255, nullable = true)
private String groupName;

@Basic
Expand Down Expand Up @@ -136,6 +144,20 @@ public void setItems(List<UpgradeItemEntity> items) {
upgradeItems = items;
}

/**
* @return the lifecycle for the group
*/
public LifecycleType getLifecycle() {
return lifecycle;
}

/**
* @param type the lifecycle for the group
*/
public void setLifecycle(LifecycleType type) {
lifecycle = type;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +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.LifecycleType;
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 @@ -1297,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(Lifecycle.LifecycleType.UPGRADE, direction);
List<Grouping> groupings = upgradePack.getGroups(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,7 +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.LifecycleType;
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 @@ -302,7 +302,7 @@ public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack,
List<UpgradeGroupHolder> groups = new ArrayList<>();

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

// !!! grouping is not scoped to context
if (!context.isScoped(group.scope)) {
Expand All @@ -318,6 +318,7 @@ public List<UpgradeGroupHolder> createSequence(UpgradePack upgradePack,

UpgradeGroupHolder groupHolder = new UpgradeGroupHolder();
groupHolder.name = group.name;
groupHolder.lifecycle = group.lifecycle;
groupHolder.title = group.title;
groupHolder.groupClass = group.getClass();
groupHolder.skippable = group.skippable;
Expand Down Expand Up @@ -700,15 +701,22 @@ private String tokenReplace(UpgradeContext ctx, String source, String service, S
* Short-lived objects that hold information about upgrade groups
*/
public static class UpgradeGroupHolder {

/**
* The lifecycle
*/
public LifecycleType lifecycle;

/**
*
*/
private boolean processingGroup;

/**
* The name
* The title
*/
public String name;

/**
* The title
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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.LifecycleType;
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 Down Expand Up @@ -225,7 +226,7 @@ public List<Grouping> getAllGroups() {
* the direction to return the ordered groups
* @return the list of groups
*/
public List<Grouping> getGroups(Lifecycle.LifecycleType type, Direction direction) {
public List<Grouping> getGroups(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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.stack.HostsType;
Expand Down Expand Up @@ -85,6 +86,9 @@ public class Grouping {
@XmlElement(name="scope")
public UpgradeScope scope = UpgradeScope.ANY;

@XmlTransient
public LifecycleType lifecycle;

/**
* A condition element with can prevent this entire group from being scheduled
* in the upgrade.
Expand Down Expand Up @@ -411,6 +415,10 @@ private void addSkippedServices(Map<String, List<OrderService>> skippedServices,
*/
@Override
public String toString() {
return Objects.toStringHelper(this).add("name", name).toString();
return Objects.toStringHelper(this)
.add("name", name)
.add("title", title)
.toString();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@
*/
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.Unmarshaller;
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;

/**
Expand All @@ -37,14 +33,14 @@
* 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>
* <li>{@link LifecycleType#INSTALL}</li>
* <li>{@link LifecycleType#QUIET}</li>
* <li>{@link LifecycleType#SNAPSHOT}</li>
* <li>{@link LifecycleType#PREPARE}</li>
* <li>{@link LifecycleType#STOP}</li>
* <li>{@link LifecycleType#UPGRADE}</li>
* <li>{@link LifecycleType#START}</li>
* <li>{@link LifecycleType#FINALIZE}</li>
* </ol>
*/
@XmlAccessorType(XmlAccessType.FIELD)
Expand All @@ -58,76 +54,16 @@ public class Lifecycle {
@XmlElement(name="group")
public List<Grouping> groups;


/**
* Identifies the lifecycle types
* Post-processes the groups for their enclosing lifecycle type
*/
@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;
protected void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
if (null == groups) {
return;
}


/**
* 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());
}
groups.stream().forEach(group -> group.lifecycle = type);
}

}