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 @@ -33,7 +33,6 @@

import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.query.QueryInfo;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.api.services.Request;
import org.apache.ambari.server.api.services.Result;
import org.apache.ambari.server.api.services.ResultImpl;
Expand Down Expand Up @@ -85,12 +84,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
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) {
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
Loading