|
|
@@ -17,25 +17,9 @@
|
|
|
*/
|
|
|
package org.apache.ambari.server.agent;
|
|
|
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOOKS_FOLDER;
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT;
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT_TYPE;
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_PACKAGE_FOLDER;
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
|
|
|
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.TreeMap;
|
|
|
|
|
|
import org.apache.ambari.server.AmbariException;
|
|
|
-import org.apache.ambari.server.RoleCommand;
|
|
|
import org.apache.ambari.server.actionmanager.ActionManager;
|
|
|
import org.apache.ambari.server.api.services.AmbariMetaInfo;
|
|
|
import org.apache.ambari.server.configuration.Configuration;
|
|
|
@@ -44,19 +28,12 @@ import org.apache.ambari.server.events.MessageNotDelivered;
|
|
|
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
|
|
|
import org.apache.ambari.server.state.Cluster;
|
|
|
import org.apache.ambari.server.state.Clusters;
|
|
|
-import org.apache.ambari.server.state.CommandScriptDefinition;
|
|
|
-import org.apache.ambari.server.state.ComponentInfo;
|
|
|
-import org.apache.ambari.server.state.Config;
|
|
|
import org.apache.ambari.server.state.ConfigHelper;
|
|
|
-import org.apache.ambari.server.state.DesiredConfig;
|
|
|
import org.apache.ambari.server.state.Host;
|
|
|
import org.apache.ambari.server.state.HostState;
|
|
|
import org.apache.ambari.server.state.Service;
|
|
|
import org.apache.ambari.server.state.ServiceComponent;
|
|
|
import org.apache.ambari.server.state.ServiceComponentHost;
|
|
|
-import org.apache.ambari.server.state.ServiceInfo;
|
|
|
-import org.apache.ambari.server.state.StackId;
|
|
|
-import org.apache.ambari.server.state.StackInfo;
|
|
|
import org.apache.ambari.server.state.State;
|
|
|
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
|
|
|
import org.apache.ambari.server.state.host.HostHeartbeatLostEvent;
|
|
|
@@ -171,161 +148,6 @@ public class HeartbeatMonitor implements Runnable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param hostname
|
|
|
- * @return list of commands to get status of service components on a concrete host
|
|
|
- */
|
|
|
- public List<StatusCommand> generateStatusCommands(String hostname) throws AmbariException {
|
|
|
- List<StatusCommand> cmds = new ArrayList<>();
|
|
|
-
|
|
|
- for (Cluster cl : clusters.getClustersForHost(hostname)) {
|
|
|
- Map<String, DesiredConfig> desiredConfigs = cl.getDesiredConfigs();
|
|
|
- for (ServiceComponentHost sch : cl.getServiceComponentHosts(hostname)) {
|
|
|
- switch (sch.getState()) {
|
|
|
- case INIT:
|
|
|
- case INSTALLING:
|
|
|
- case STARTING:
|
|
|
- case STOPPING:
|
|
|
- //don't send commands until component is installed at least
|
|
|
- continue;
|
|
|
- default:
|
|
|
- StatusCommand statusCmd = createStatusCommand(hostname, cl, sch, desiredConfigs);
|
|
|
- cmds.add(statusCmd);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- return cmds;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Generates status command and fills all appropriate fields.
|
|
|
- * @throws AmbariException
|
|
|
- */
|
|
|
- private StatusCommand createStatusCommand(String hostname, Cluster cluster,
|
|
|
- ServiceComponentHost sch, Map<String, DesiredConfig> desiredConfigs) throws AmbariException {
|
|
|
- String serviceName = sch.getServiceName();
|
|
|
- String serviceType = sch.getServiceType();
|
|
|
- String componentName = sch.getServiceComponentName();
|
|
|
-
|
|
|
- StackId stackId = sch.getDesiredStackId();
|
|
|
-
|
|
|
- ServiceInfo serviceInfo = ambariMetaInfo.getService(stackId.getStackName(),
|
|
|
- stackId.getStackVersion(), serviceType);
|
|
|
- ComponentInfo componentInfo = ambariMetaInfo.getComponent(
|
|
|
- stackId.getStackName(), stackId.getStackVersion(),
|
|
|
- serviceType, componentName);
|
|
|
- StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(),
|
|
|
- stackId.getStackVersion());
|
|
|
-
|
|
|
- Map<String, Map<String, String>> configurations = new TreeMap<>();
|
|
|
- Map<String, Map<String, Map<String, String>>> configurationAttributes = new TreeMap<>();
|
|
|
-
|
|
|
- // get the cluster config for type '*-env'
|
|
|
- // apply config group overrides
|
|
|
- //Config clusterConfig = cluster.getDesiredConfigByType(GLOBAL);
|
|
|
- Collection<Config> clusterConfigs = cluster.getAllConfigs();
|
|
|
-
|
|
|
- // creating list with desired config types to validate if cluster config actual
|
|
|
- Set<String> desiredConfigTypes = desiredConfigs.keySet();
|
|
|
-
|
|
|
- // Apply global properties for this host from all config groups
|
|
|
- Map<String, Map<String, String>> allConfigTags = configHelper
|
|
|
- .getEffectiveDesiredTags(cluster, hostname);
|
|
|
-
|
|
|
- for(Config clusterConfig: clusterConfigs) {
|
|
|
- String configType = clusterConfig.getType();
|
|
|
- if(!configType.endsWith("-env") || !desiredConfigTypes.contains(configType)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // cluster config for 'global'
|
|
|
- Map<String, String> props = new HashMap<>(clusterConfig.getProperties());
|
|
|
-
|
|
|
- Map<String, Map<String, String>> configTags = new HashMap<>();
|
|
|
-
|
|
|
- for (Map.Entry<String, Map<String, String>> entry : allConfigTags.entrySet()) {
|
|
|
- if (entry.getKey().equals(clusterConfig.getType())) {
|
|
|
- configTags.put(clusterConfig.getType(), entry.getValue());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Map<String, String>> properties = configHelper
|
|
|
- .getEffectiveConfigProperties(cluster, configTags);
|
|
|
-
|
|
|
- if (!properties.isEmpty()) {
|
|
|
- for (Map<String, String> propertyMap : properties.values()) {
|
|
|
- props.putAll(propertyMap);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- configurations.put(clusterConfig.getType(), props);
|
|
|
-
|
|
|
- Map<String, Map<String, String>> attrs = new TreeMap<>();
|
|
|
- configHelper.cloneAttributesMap(clusterConfig.getPropertiesAttributes(), attrs);
|
|
|
-
|
|
|
- Map<String, Map<String, Map<String, String>>> attributes = configHelper
|
|
|
- .getEffectiveConfigAttributes(cluster, configTags);
|
|
|
- for (Map<String, Map<String, String>> attributesMap : attributes.values()) {
|
|
|
- configHelper.cloneAttributesMap(attributesMap, attrs);
|
|
|
- }
|
|
|
- configurationAttributes.put(clusterConfig.getType(), attrs);
|
|
|
- }
|
|
|
-
|
|
|
- StatusCommand statusCmd = new StatusCommand();
|
|
|
- statusCmd.setClusterName(cluster.getClusterName());
|
|
|
- statusCmd.setServiceName(serviceName);
|
|
|
- statusCmd.setServiceType(serviceType);
|
|
|
- statusCmd.setComponentName(componentName);
|
|
|
- statusCmd.setConfigurations(configurations);
|
|
|
- statusCmd.setConfigurationAttributes(configurationAttributes);
|
|
|
- statusCmd.setHostname(hostname);
|
|
|
-
|
|
|
- // If Agent wants the command and the States differ
|
|
|
- statusCmd.setDesiredState(sch.getDesiredState());
|
|
|
- statusCmd.setHasStaleConfigs(configHelper.isStaleConfigs(sch, desiredConfigs));
|
|
|
- if (getAgentRequests().shouldSendExecutionDetails(hostname, componentName)) {
|
|
|
- LOG.info(componentName + " is at " + sch.getState() + " adding more payload per agent ask");
|
|
|
- statusCmd.setPayloadLevel(StatusCommand.StatusCommandPayload.EXECUTION_COMMAND);
|
|
|
- }
|
|
|
-
|
|
|
- // Fill command params
|
|
|
- Map<String, String> commandParams = statusCmd.getCommandParams();
|
|
|
-
|
|
|
- String commandTimeout = configuration.getDefaultAgentTaskTimeout(false);
|
|
|
- CommandScriptDefinition script = componentInfo.getCommandScript();
|
|
|
- if (serviceInfo.getSchemaVersion().equals(AmbariMetaInfo.SCHEMA_VERSION_2)) {
|
|
|
- if (script != null) {
|
|
|
- commandParams.put(SCRIPT, script.getScript());
|
|
|
- commandParams.put(SCRIPT_TYPE, script.getScriptType().toString());
|
|
|
- if (script.getTimeout() > 0) {
|
|
|
- commandTimeout = String.valueOf(script.getTimeout());
|
|
|
- }
|
|
|
- } else {
|
|
|
- String message = String.format("Component %s of service %s has not " +
|
|
|
- "command script defined", componentName, serviceName);
|
|
|
- throw new AmbariException(message);
|
|
|
- }
|
|
|
- }
|
|
|
- commandParams.put(COMMAND_TIMEOUT, commandTimeout);
|
|
|
- commandParams.put(SERVICE_PACKAGE_FOLDER,
|
|
|
- serviceInfo.getServicePackageFolder());
|
|
|
- commandParams.put(HOOKS_FOLDER, configuration.getProperty(Configuration.HOOKS_FOLDER));
|
|
|
- // Fill host level params
|
|
|
- Map<String, String> hostLevelParams = statusCmd.getHostLevelParams();
|
|
|
- hostLevelParams.put(JDK_LOCATION, ambariManagementController.getJdkResourceUrl());
|
|
|
- hostLevelParams.put(STACK_NAME, stackId.getStackName());
|
|
|
- hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());
|
|
|
-
|
|
|
- if (statusCmd.getPayloadLevel() == StatusCommand.StatusCommandPayload.EXECUTION_COMMAND) {
|
|
|
- ExecutionCommand ec = ambariManagementController.getExecutionCommand(cluster, sch, RoleCommand.START);
|
|
|
- statusCmd.setExecutionCommand(ec);
|
|
|
- LOG.debug("{} has more payload for execution command", componentName);
|
|
|
- }
|
|
|
-
|
|
|
- return statusCmd;
|
|
|
- }
|
|
|
-
|
|
|
private void handleHeartbeatLost(Long hostId) throws AmbariException, InvalidStateTransitionException {
|
|
|
Host hostObj = clusters.getHostById(hostId);
|
|
|
String host = hostObj.getHostName();
|