Search in sources :

Example 1 with CloudbreakClient

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));
    }
}
Also used : CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.periscope.domain.Cluster) Map(java.util.Map) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 2 with CloudbreakClient

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);
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) JobExecutionContext(org.quartz.JobExecutionContext) EvaluatorContext(com.sequenceiq.periscope.monitor.evaluator.EvaluatorContext) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) Set(java.util.Set) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ApplicationContext(org.springframework.context.ApplicationContext) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator) Status(com.sequenceiq.cloudbreak.api.model.Status) List(java.util.List) Component(org.springframework.stereotype.Component) JobDataMap(org.quartz.JobDataMap) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) ExecutorService(java.util.concurrent.ExecutorService) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Cluster(com.sequenceiq.periscope.domain.Cluster) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator)

Example 3 with CloudbreakClient

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);
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient)

Example 4 with CloudbreakClient

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));
    }
}
Also used : CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) CloudbreakClientBuilder(com.sequenceiq.cloudbreak.client.CloudbreakClient.CloudbreakClientBuilder) Parameters(org.testng.annotations.Parameters) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 5 with CloudbreakClient

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;
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) Arrays(java.util.Arrays) HostMetadataResponse(com.sequenceiq.cloudbreak.api.model.HostMetadataResponse) HostGroupResponse(com.sequenceiq.cloudbreak.api.model.HostGroupResponse) LoggerFactory(org.slf4j.LoggerFactory) AutoscaleClusterHistoryResponse(com.sequenceiq.periscope.api.model.AutoscaleClusterHistoryResponse) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) HashMap(java.util.HashMap) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) AutoscaleClient(com.sequenceiq.periscope.client.AutoscaleClient) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) Status(com.sequenceiq.cloudbreak.api.model.Status) StackEndpoint(com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint) Assert(org.testng.Assert) Map(java.util.Map) FALSE(java.lang.Boolean.FALSE) Logger(org.slf4j.Logger) HistoryEndpoint(com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint) Collection(java.util.Collection) Set(java.util.Set) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) Family(javax.ws.rs.core.Response.Status.Family) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StringUtils(org.springframework.util.StringUtils) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HashMap(java.util.HashMap) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackEndpoint(com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint) HistoryEndpoint(com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)

Aggregations

CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)10 Cluster (com.sequenceiq.periscope.domain.Cluster)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)3 Collections (java.util.Collections)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Component (org.springframework.stereotype.Component)3 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)2 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)2 FailureReport (com.sequenceiq.cloudbreak.api.model.FailureReport)2 Status (com.sequenceiq.cloudbreak.api.model.Status)2 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)2 ClusterService (com.sequenceiq.periscope.service.ClusterService)2 CloudbreakClientConfiguration (com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration)2 List (java.util.List)2 Set (java.util.Set)2 AfterSuite (org.testng.annotations.AfterSuite)2 Parameters (org.testng.annotations.Parameters)2