use of com.sequenceiq.cloudbreak.client.CloudbreakClient in project cloudbreak by hortonworks.
the class AmbariAgentHealthEvaluator method run.
@Override
public void run() {
Cluster cluster = clusterService.find(clusterId);
MDCBuilder.buildMdcContext(cluster);
LOGGER.info("Checking '{}' alerts.", AMBARI_AGENT_HEARTBEAT);
try {
AmbariClient ambariClient = ambariClientProvider.createAmbariClient(cluster);
List<Map<String, Object>> alertHistory = ambariClient.getAlert(AMBARI_AGENT_HEARTBEAT_DEF_NAME);
if (!alertHistory.isEmpty()) {
List<String> hostNamesToRecover = new ArrayList<>();
for (Map<String, Object> history : alertHistory) {
String currentState = (String) history.get(ALERT_STATE);
if (isAlertStateMet(currentState)) {
String hostName = (String) history.get(HOST_NAME);
hostNamesToRecover.add(hostName);
LOGGER.info("Alert: {} is in '{}' state for host '{}'.", AMBARI_AGENT_HEARTBEAT, currentState, hostName);
}
}
if (!hostNamesToRecover.isEmpty()) {
hostNamesToRecover.forEach(hn -> LOGGER.info("Host to recover: {}", hn));
CloudbreakClient cbClient = cloudbreakClientConfiguration.cloudbreakClient();
FailureReport failureReport = new FailureReport();
failureReport.setFailedNodes(hostNamesToRecover);
cbClient.clusterEndpoint().failureReport(cluster.getStackId(), failureReport);
}
}
} catch (Exception e) {
LOGGER.warn(String.format("Failed to retrieve '%s' alerts.", AMBARI_AGENT_HEARTBEAT), e);
publishEvent(new UpdateFailedEvent(clusterId));
}
}
use of com.sequenceiq.cloudbreak.client.CloudbreakClient in project cloudbreak by hortonworks.
the class ClusterMonitor method execute.
@Override
public void execute(JobExecutionContext context) {
evalContext(context);
try {
CloudbreakClient cloudbreakClient = applicationContext.getBean(CloudbreakClientConfiguration.class).cloudbreakClient();
ClusterService clusterService = applicationContext.getBean(ClusterService.class);
List<Cluster> clusters = clusterService.findAll();
Set<AutoscaleStackResponse> allStacks = cloudbreakClient.stackV1Endpoint().getAllForAutoscale();
for (AutoscaleStackResponse stack : allStacks) {
Status clusterStatus = stack.getClusterStatus();
if (clusterStatus != null && AVAILABLE.equals(clusterStatus)) {
String ambariIp = stack.getAmbariServerIp();
Optional<Cluster> clusterOptional = clusters.stream().filter(c -> c.getStackId() != null && c.getStackId().equals(stack.getStackId())).findFirst();
if (ambariIp != null) {
ClusterCreationEvaluator clusterCreationEvaluator = applicationContext.getBean(ClusterCreationEvaluator.class);
clusterCreationEvaluator.setContext(new ClusterCreationEvaluatorContext(stack, clusterOptional));
executorService.submit(clusterCreationEvaluator);
} else {
LOGGER.info("Could not find Ambari for stack: {}(ID:{})", stack.getName(), stack.getStackId());
}
} else {
LOGGER.info("Do not create or update cluster while the Cloudbreak cluster {}(ID:{}) is in '{}' state instead of 'AVAILABLE'!", stack.getName(), stack.getStackId(), stack.getClusterStatus());
}
}
} catch (Exception ex) {
LOGGER.error("New clusters could not be synchronized from Cloudbreak.", ex);
}
}
use of com.sequenceiq.cloudbreak.client.CloudbreakClient in project cloudbreak by hortonworks.
the class AutoscalingUtil method checkScaling.
static void checkScaling(IntegrationTestContext itContext, CloudbreakClient cloudbreakClient, int scalingAdjustment, String stackId, int expectedNodeCountStack, int expectedNodeCountCluster) {
String ambariUser = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID);
String ambariPassword = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID);
String ambariPort = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PORT_ID);
StackV1Endpoint stackV1Endpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint();
if (scalingAdjustment < 0) {
CloudbreakUtil.waitAndCheckClusterStatus(cloudbreakClient, stackId, "AVAILABLE");
CloudbreakUtil.waitAndCheckStackStatus(cloudbreakClient, stackId, "AVAILABLE");
} else {
CloudbreakUtil.waitAndCheckStackStatus(cloudbreakClient, stackId, "AVAILABLE");
CloudbreakUtil.waitAndCheckClusterStatus(cloudbreakClient, stackId, "AVAILABLE");
}
ScalingUtil.checkStackScaled(stackV1Endpoint, stackId, expectedNodeCountStack);
ScalingUtil.checkClusterScaled(stackV1Endpoint, ambariPort, stackId, ambariUser, ambariPassword, expectedNodeCountCluster, itContext);
ScalingUtil.putInstanceCountToContext(itContext, stackId);
}
use of com.sequenceiq.cloudbreak.client.CloudbreakClient in project cloudbreak by hortonworks.
the class CloudbreakTestSuiteInitializer method initCloudbreakSuite.
@BeforeSuite(dependsOnMethods = "initContext")
@Parameters({ "cloudbreakServer", "cloudProvider", "credentialName", "instanceGroups", "hostGroups", "blueprintName", "stackName", "networkName", "securityGroupName" })
public void initCloudbreakSuite(@Optional("") String cloudbreakServer, @Optional("") String cloudProvider, @Optional("") String credentialName, @Optional("") String instanceGroups, @Optional("") String hostGroups, @Optional("") String blueprintName, @Optional("") String stackName, @Optional("") String networkName, @Optional("") String securityGroupName) {
cloudbreakServer = StringUtils.hasLength(cloudbreakServer) ? cloudbreakServer : defaultCloudbreakServer;
String cbServerRoot = cloudbreakServer + cbRootContextPath;
itContext.putContextParam(CloudbreakITContextConstants.SKIP_REMAINING_SUITETEST_AFTER_ONE_FAILED, skipRemainingSuiteTestsAfterOneFailed);
itContext.putContextParam(CloudbreakITContextConstants.CLOUDBREAK_SERVER, cloudbreakServer);
itContext.putContextParam(CloudbreakITContextConstants.CLOUDBREAK_SERVER_ROOT, cbServerRoot);
itContext.putContextParam(CloudbreakITContextConstants.CLOUDPROVIDER, cloudProvider);
String identity = itContext.getContextParam(IntegrationTestContext.IDENTITY_URL);
String user = itContext.getContextParam(IntegrationTestContext.AUTH_USER);
String password = itContext.getContextParam(IntegrationTestContext.AUTH_PASSWORD);
CloudbreakClient cloudbreakClient = new CloudbreakClientBuilder(cbServerRoot, identity, "cloudbreak_shell").withCertificateValidation(false).withIgnorePreValidation(true).withDebug(true).withCredential(user, password).build();
itContext.putContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, cloudbreakClient);
if (cleanUpBeforeStart) {
cleanUpService.deleteTestStacksAndResources(cloudbreakClient);
}
putBlueprintToContextIfExist(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).blueprintEndpoint(), blueprintName);
putNetworkToContext(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).networkEndpoint(), cloudProvider, networkName);
putSecurityGroupToContext(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).securityGroupEndpoint(), cloudProvider, securityGroupName);
putCredentialToContext(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).credentialEndpoint(), cloudProvider, credentialName);
putStackToContextIfExist(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint(), stackName);
if (StringUtils.hasLength(instanceGroups)) {
List<String[]> instanceGroupStrings = templateAdditionHelper.parseCommaSeparatedRows(instanceGroups);
itContext.putContextParam(CloudbreakITContextConstants.TEMPLATE_ID, createInstanceGroups(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).templateEndpoint(), instanceGroupStrings));
}
if (StringUtils.hasLength(hostGroups)) {
List<String[]> hostGroupStrings = templateAdditionHelper.parseCommaSeparatedRows(hostGroups);
itContext.putContextParam(CloudbreakITContextConstants.HOSTGROUP_ID, createHostGroups(hostGroupStrings));
}
}
use of com.sequenceiq.cloudbreak.client.CloudbreakClient in project cloudbreak by hortonworks.
the class CloudbreakUtil method waitForStatuses.
private static WaitResult waitForStatuses(CloudbreakClient cloudbreakClient, String stackId, Map<String, String> desiredStatuses) {
WaitResult waitResult = WaitResult.SUCCESSFUL;
Map<String, String> currentStatuses = new HashMap<>();
int retryCount = 0;
do {
LOGGER.info("Waiting for status(es) {}, stack id: {}, current status(es) {} ...", desiredStatuses, stackId, currentStatuses);
sleep();
StackV1Endpoint stackV1Endpoint = cloudbreakClient.stackV1Endpoint();
try {
Map<String, Object> statusResult = stackV1Endpoint.status(Long.valueOf(stackId));
for (String statusPath : desiredStatuses.keySet()) {
currentStatuses.put(statusPath, (String) statusResult.get(statusPath));
}
} catch (RuntimeException ignore) {
continue;
}
retryCount++;
} while (!checkStatuses(currentStatuses, desiredStatuses) && !checkFailedStatuses(currentStatuses) && retryCount < MAX_RETRY);
LOGGER.info("Status(es) {} for {} are in desired status(es) {}", desiredStatuses.keySet(), stackId, currentStatuses.values());
if (currentStatuses.values().stream().anyMatch(cs -> cs.contains("FAILED")) || checkNotExpectedDelete(currentStatuses, desiredStatuses)) {
waitResult = WaitResult.FAILED;
}
if (retryCount == MAX_RETRY) {
waitResult = WaitResult.TIMEOUT;
}
return waitResult;
}
Aggregations