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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3163,31 +3163,31 @@ protected RequestStageContainer doStageCreation(RequestStageContainer requestSta
}

for (Service service : smokeTestServices) { // Creates smoke test commands
// find service component host
ServiceComponent component = getClientComponentForRunningAction(cluster, service);
String componentName = component != null ? component.getName() : null;
String clientHost = getClientHostForRunningAction(cluster, service, component);
String smokeTestRole = actionMetadata.getServiceCheckAction(service.getServiceType());
try {
// find service component host
ServiceComponentHost componentForServiceCheck = customCommandExecutionHelper.
calculateServiceComponentHostForServiceCheck(cluster, service);

if (StringUtils.isBlank(stage.getHostParamsStage())) {
RepositoryVersionEntity repositoryVersion = componentForServiceCheck.getServiceComponent().getDesiredRepositoryVersion();
stage.setHostParamsStage(StageUtils.getGson().toJson(
customCommandExecutionHelper.createDefaultHostParams(cluster, repositoryVersion.getStackId())));
}

if (clientHost == null || smokeTestRole == null) {
LOG.info("Nothing to do for service check as could not find role or"
+ " or host to run check on"
+ ", clusterName=" + cluster.getClusterName()
+ ", serviceGroupName=" + service.getServiceGroupName()
+ ", serviceName=" + service.getName()
+ ", clientHost=" + clientHost
+ ", serviceCheckRole=" + smokeTestRole);
continue;
}

if (StringUtils.isBlank(stage.getHostParamsStage())) {
RepositoryVersionEntity repositoryVersion = component.getDesiredRepositoryVersion();
stage.setHostParamsStage(StageUtils.getGson().toJson(
customCommandExecutionHelper.createDefaultHostParams(cluster, repositoryVersion.getStackId())));
customCommandExecutionHelper.addServiceCheckAction(stage, componentForServiceCheck.getHostName(), smokeTestRole,
nowTimestamp, componentForServiceCheck.getServiceGroupName(), componentForServiceCheck.getServiceName(),
componentForServiceCheck.getServiceComponentName(), null, false, false, service.getName());

} catch (AmbariException e) {
LOG.warn("Nothing to do for service check as could not find role or"
+ " or host to run check on"
+ ", clusterName=" + cluster.getClusterName()
+ ", serviceGroupName=" + service.getServiceGroupName()
+ ", serviceName=" + service.getName()
+ ", serviceCheckRole=" + smokeTestRole
+ "Actual reason : " + e.getMessage());
}

customCommandExecutionHelper.addServiceCheckAction(stage, clientHost, smokeTestRole,
nowTimestamp, service.getServiceGroupName(), service.getName(), componentName, null, false, false);
}

RoleCommandOrder rco = getRoleCommandOrder(cluster);
Expand Down Expand Up @@ -3988,79 +3988,6 @@ public void updateGroups(Set<GroupRequest> requests) throws AmbariException {
// currently no group updates are supported
}

protected String getClientHostForRunningAction(Cluster cluster, Service service, ServiceComponent serviceComponent)
throws AmbariException {
if (serviceComponent != null && !serviceComponent.getServiceComponentHosts().isEmpty()) {
Set<String> candidateHosts = serviceComponent.getServiceComponentHosts().keySet();
filterHostsForAction(candidateHosts, service, cluster, Resource.Type.Cluster);
return getHealthyHost(candidateHosts);
}
return null;
}

protected ServiceComponent getClientComponentForRunningAction(Cluster cluster,
Service service) throws AmbariException {
/*
* We assume Cluster level here. That means that we never run service
* checks on clients/hosts that are in maintenance state.
* That also means that we can not run service check if the only host
* that has client component is in maintenance state
*/

StackId stackId = service.getDesiredStackId();
ComponentInfo compInfo =
ambariMetaInfo.getService(stackId.getStackName(),
stackId.getStackVersion(), service.getServiceType()).getClientComponent();
if (compInfo != null) {
try {
ServiceComponent serviceComponent =
service.getServiceComponent(compInfo.getName());
if (!serviceComponent.getServiceComponentHosts().isEmpty()) {
return serviceComponent;
}
} catch (ServiceComponentNotFoundException e) {
LOG.warn("Could not find required component to run action"
+ ", clusterName=" + cluster.getClusterName()
+ ", serviceName=" + service.getName()
+ ", componentName=" + compInfo.getName());
}
}

// any component will do
Map<String, ServiceComponent> components = service.getServiceComponents();
if (!components.isEmpty()) {
for (ServiceComponent serviceComponent : components.values()) {
if (!serviceComponent.getServiceComponentHosts().isEmpty()) {
return serviceComponent;
}
}
}
return null;
}

/**
* Utility method that filters out hosts from set based on their maintenance
* state status.
*/
protected void filterHostsForAction(Set<String> candidateHosts, Service service,
final Cluster cluster,
final Resource.Type level)
throws AmbariException {
Set<String> ignoredHosts = maintenanceStateHelper.filterHostsInMaintenanceState(
candidateHosts, new MaintenanceStateHelper.HostPredicate() {
@Override
public boolean shouldHostBeRemoved(final String hostname)
throws AmbariException {
Host host = clusters.getHost(hostname);
return !maintenanceStateHelper.isOperationAllowed(
host, cluster.getClusterId(), level);
}
}
);
LOG.debug("Ignoring hosts when selecting available hosts for action due to maintenance state.Ignored hosts ={}, cluster={}, service={}",
ignoredHosts, cluster.getClusterName(), service.getName());
}

/**
* Filters hosts to only select healthy ones that are heartbeating.
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class CommandScriptDefinition {
*/
private int timeout = 0;

private String clientComponentType = null;


public String getScript() {
return script;
Expand All @@ -57,6 +59,10 @@ public int getTimeout() {
return timeout;
}

public String getClientComponentType() {
return clientComponentType;
}

public enum Type {
PYTHON
}
Expand All @@ -77,14 +83,16 @@ public boolean equals(Object obj) {
return new EqualsBuilder().
append(script, rhs.script).
append(scriptType, rhs.scriptType).
append(timeout, rhs.timeout).isEquals();
append(timeout, rhs.timeout).
append(clientComponentType, rhs.clientComponentType).isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 31).
append(script).
append(scriptType).
append(timeout).toHashCode();
append(timeout).
append(clientComponentType).toHashCode();
}
}
Loading