Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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 @@ -85,12 +85,6 @@ public class ClusterBlueprintRenderer extends BaseRenderer implements Renderer {
*/
private AmbariManagementController controller = AmbariServer.getController();


/**
* MetaInfo used to get stack and mpack information.
*/
private AmbariMetaInfo metaInfo = controller.getAmbariMetaInfo();

// /**
// * Map of configuration type to configuration properties which are required that a user
// * input. These properties will be stripped from the exported blueprint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.apache.ambari.server.controller.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -29,15 +31,17 @@
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.orm.entities.TopologyHostGroupEntity;
import org.apache.ambari.server.orm.entities.TopologyHostInfoEntity;
import org.apache.ambari.server.orm.entities.TopologyRequestEntity;
import org.apache.ambari.server.topology.Blueprint;
import org.apache.ambari.server.topology.BlueprintFactory;
import org.apache.ambari.server.topology.Configuration;
import org.apache.ambari.server.topology.HostGroupInfo;
import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
import org.apache.ambari.server.topology.SecurityConfiguration;
import org.apache.ambari.server.topology.TopologyRequest;
import org.apache.ambari.server.topology.TopologyRequestUtil;
import org.apache.ambari.server.utils.JsonUtils;

/**
* Provides common cluster request functionality.
Expand All @@ -55,11 +59,6 @@ public abstract class BaseClusterRequest implements TopologyRequest {

protected ProvisionAction provisionAction;

/**
* The raw request body. We would like to persist it.
*/
protected String rawRequestBody;

/**
* cluster id
*/
Expand Down Expand Up @@ -125,19 +124,6 @@ public Map<String, HostGroupInfo> getHostGroupInfo() {
return hostGroupInfoMap;
}

/**
* @return the raw request body in JSON string
*/
public String getRawRequestBody() {
return rawRequestBody;
}

@Override
public Set<StackId> getStackIds() {
return TopologyRequestUtil.getStackIdsFromRequest(
TopologyRequestUtil.getPropertyMap(rawRequestBody));
}

/**
* Validate that all properties specified in the predicate are valid for the Host resource.
*
Expand Down Expand Up @@ -224,4 +210,77 @@ public ProvisionAction getProvisionAction() {
public void setProvisionAction(ProvisionAction provisionAction) {
this.provisionAction = provisionAction;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is moved here from PersistedStateImpl to take advantage of polymorphism instead of doing instanceof checks.

/**
* @return the request converted to a {@link TopologyRequestEntity}
*/
public TopologyRequestEntity toEntity() {
TopologyRequestEntity entity = new TopologyRequestEntity();

//todo: this isn't set for a scaling operation because we had intended to allow multiple
//todo: bp's to be used to scale a cluster although this isn't currently supported by
//todo: new topology infrastructure
entity.setAction(getType().name());
if (getBlueprint() != null) {
entity.setBlueprintName(getBlueprint().getName());
}

entity.setClusterAttributes(JsonUtils.toJson(getConfiguration().getAttributes()));
entity.setClusterId(getClusterId());
entity.setClusterProperties(JsonUtils.toJson(getConfiguration().getProperties()));
entity.setDescription(getDescription());

if (getProvisionAction() != null) {
entity.setProvisionAction(getProvisionAction());
}

// host groups
Collection<TopologyHostGroupEntity> hostGroupEntities = new ArrayList<>();
for (HostGroupInfo groupInfo : getHostGroupInfo().values()) {
hostGroupEntities.add(toHostGroupEntity(groupInfo, entity));
}
entity.setTopologyHostGroupEntities(hostGroupEntities);

return entity;
}

/**
* Converts a {@link HostGroupInfo} to a {@link TopologyHostGroupEntity}
* @param groupInfo the {@link HostGroupInfo} to convert
* @param topologyRequestEntity the base entity to add the host group to
* @return the resulting {@link TopologyHostGroupEntity}
*/
private TopologyHostGroupEntity toHostGroupEntity(HostGroupInfo groupInfo, TopologyRequestEntity topologyRequestEntity) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doc.

TopologyHostGroupEntity entity = new TopologyHostGroupEntity();
entity.setGroupAttributes(JsonUtils.toJson(groupInfo.getConfiguration().getAttributes()));
entity.setGroupProperties(JsonUtils.toJson(groupInfo.getConfiguration().getProperties()));
entity.setName(groupInfo.getHostGroupName());
entity.setTopologyRequestEntity(topologyRequestEntity);

// host info
Collection<TopologyHostInfoEntity> hostInfoEntities = new ArrayList<>();
entity.setTopologyHostInfoEntities(hostInfoEntities);

Collection<String> hosts = groupInfo.getHostNames();
if (hosts.isEmpty()) {
TopologyHostInfoEntity hostInfoEntity = new TopologyHostInfoEntity();
hostInfoEntity.setTopologyHostGroupEntity(entity);
hostInfoEntity.setHostCount(groupInfo.getRequestedHostCount());
if (groupInfo.getPredicate() != null) {
hostInfoEntity.setPredicate(groupInfo.getPredicateString());
}
hostInfoEntities.add(hostInfoEntity);
} else {
for (String hostName : hosts) {
TopologyHostInfoEntity hostInfoEntity = new TopologyHostInfoEntity();
hostInfoEntity.setTopologyHostGroupEntity(entity);
hostInfoEntity.setPredicate(groupInfo.getPredicateString());
hostInfoEntity.setFqdn(hostName);
hostInfoEntity.setRackInfo(groupInfo.getHostRackInfo().get(hostName));
hostInfoEntity.setHostCount(0);
hostInfoEntities.add(hostInfoEntity);
}
}
return entity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private RequestStatusResponse processBlueprintCreate(Map<String, Object> propert
ProvisionClusterRequest createClusterRequest;
try {
createClusterRequest =
topologyRequestFactory.createProvisionClusterRequest(rawRequestBody, properties, securityConfiguration);
topologyRequestFactory.createProvisionClusterRequest(properties, securityConfiguration);
} catch (InvalidTopologyTemplateException e) {
throw new IllegalArgumentException("Invalid Cluster Creation Template: " + e, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,7 @@ public static String getHostNameFromProperties(Map<String, Object> properties) {
private RequestStatusResponse submitHostRequests(Request request) throws SystemException {
ScaleClusterRequest requestRequest;
try {
requestRequest = new ScaleClusterRequest(
request.getRequestInfoProperties().get(Request.REQUEST_INFO_BODY_PROPERTY),
request.getProperties());
requestRequest = new ScaleClusterRequest(request.getProperties());
} catch (InvalidTopologyTemplateException e) {
throw new IllegalArgumentException("Invalid Add Hosts Template: " + e, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Set;

import org.apache.ambari.server.api.predicate.InvalidQueryException;
import org.apache.ambari.server.orm.entities.TopologyRequestEntity;
import org.apache.ambari.server.orm.entities.TopologyRequestMpackInstanceEntity;
import org.apache.ambari.server.security.encryption.CredentialStoreType;
import org.apache.ambari.server.stack.NoSuchStackException;
import org.apache.ambari.server.state.SecurityType;
Expand Down Expand Up @@ -174,9 +176,8 @@ public class ProvisionClusterRequest extends BaseClusterRequest implements Provi
* @param properties request properties
* @param securityConfiguration security config related properties
*/
public ProvisionClusterRequest(String rawRequestBody, Map<String, Object> properties, SecurityConfiguration securityConfiguration) throws
InvalidTopologyTemplateException {
this.rawRequestBody = rawRequestBody;
public ProvisionClusterRequest(Map<String, Object> properties, SecurityConfiguration securityConfiguration) throws
InvalidTopologyTemplateException {

setClusterName(String.valueOf(properties.get(
ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID)));
Expand Down Expand Up @@ -535,4 +536,16 @@ public Set<StackId> getStackIds() {
public Collection<MpackInstance> getMpacks() {
return mpackInstances;
}

@Override
public TopologyRequestEntity toEntity() {
TopologyRequestEntity entity = super.toEntity();
mpackInstances.forEach(mpackInstance -> {
TopologyRequestMpackInstanceEntity mpackInstanceEntity = mpackInstance.toMpackInstanceEntity(entity);
entity.getMpackInstances().add(mpackInstanceEntity);
});
return entity;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public class ScaleClusterRequest extends BaseClusterRequest {
*
* @throws InvalidTopologyTemplateException if any validation of properties fails
*/
public ScaleClusterRequest(String rawRequestBody, Set<Map<String, Object>> propertySet) throws InvalidTopologyTemplateException {
this.rawRequestBody = rawRequestBody;
public ScaleClusterRequest(Set<Map<String, Object>> propertySet) throws InvalidTopologyTemplateException {
for (Map<String, Object> properties : propertySet) {
// can only operate on a single cluster per logical request
if (getClusterName() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,133 +18,22 @@

package org.apache.ambari.server.orm.entities;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Nullable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

/**
* Entity to encapsulate a blueprint's use of an mpack. It contains the mpack name, version, url
*
*
* referencing a management pack from the blueprint. The reference contains the name and
* the version of the mpack, but no direct database reference to the mpack entity as a blueprint
* can be saved without the referenced mpack being present.
* Mpack instance entity for blueprints
*/
@Entity
@Table(name = "blueprint_mpack_instance")
@TableGenerator(name = "blueprint_mpack_instance_id_generator", table = "ambari_sequences", pkColumnName = "sequence_name",
valueColumnName = "sequence_value", pkColumnValue = "blueprint_mpack_instance_id_seq", initialValue = 1)
public class BlueprintMpackInstanceEntity {
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "blueprint_mpack_instance_id_generator")
@Column(name = "id", nullable = false, updatable = false)
private Long id;

@Column(name = "mpack_name", nullable = false)
private String mpackName;

@Column(name = "mpack_version", nullable = false)
private String mpackVersion;

@Column(name = "mpack_uri")
private String mpackUri;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "mpackInstance")
private Collection<BlueprintServiceEntity> serviceInstances = new ArrayList<>();

@OneToMany(cascade = CascadeType.ALL, mappedBy = "mpackInstance")
private Collection<BlueprintMpackConfigEntity> configurations = new ArrayList<>();
@DiscriminatorValue("Blueprint")
public class BlueprintMpackInstanceEntity extends MpackInstanceEntity {

@ManyToOne
@JoinColumn(name = "mpack_id", referencedColumnName = "id")
private MpackEntity mpackEntity;

@ManyToOne
@JoinColumn(name = "blueprint_name", referencedColumnName = "blueprint_name", nullable = false)
@JoinColumn(name = "blueprint_name", referencedColumnName = "blueprint_name")
private BlueprintEntity blueprint;

/**
* @return the service instances belonging to this mpack
*/
public Collection<BlueprintServiceEntity> getServiceInstances() {
return serviceInstances;
}

/**
* @param serviceInstances the service instances belonging to this mpack
*/
public void setServiceInstances(Collection<BlueprintServiceEntity> serviceInstances) {
this.serviceInstances = serviceInstances;
}

/**
* @return the name of the mpack
*/
public String getMpackName() {
return mpackName;
}

/**
* @param mpackName the name of the mpack
*/
public void setMpackName(String mpackName) {
this.mpackName = mpackName;
}

/**
* @return the version of the mpack
*/
public String getMpackVersion() {
return mpackVersion;
}

/**
* @param mpackVersion the version of the mpack
*/
public void setMpackVersion(String mpackVersion) {
this.mpackVersion = mpackVersion;
}

/**
* @return the uri of the mpack
*/
public String getMpackUri() {
return mpackUri;
}

/**
* @param mpackUri the uri of the mpack
*/
public void setMpackUri(String mpackUri) {
this.mpackUri = mpackUri;
}

/**
* @return the database id
*/
public Long getId() {
return id;
}

/**
* @param id the database id
*/
public void setId(Long id) {
this.id = id;
}

/**
* @return the blueprint
*/
Expand All @@ -159,32 +48,8 @@ public void setBlueprint(BlueprintEntity blueprint) {
this.blueprint = blueprint;
}

/**
* @return the mpack level configurations for this mpack
*/
public Collection<BlueprintMpackConfigEntity> getConfigurations() {
return configurations;
}

/**
* @param configurations the mpack level configurations for this mpack
*/
public void setConfigurations(Collection<BlueprintMpackConfigEntity> configurations) {
this.configurations = configurations;
}

/**
* @return the management pack entity associated with this blueprint. Can be {@null}
*/
@Nullable
public MpackEntity getMpackEntity() {
return mpackEntity;
}

/**
* @param mpackEntity the management pack entity to be associated with this blueprint.
*/
public void setMpackEntity(MpackEntity mpackEntity) {
this.mpackEntity = mpackEntity;
@Override
public String getBlueprintName() {
return blueprint.getBlueprintName();
}
}
Loading