Search in sources :

Example 1 with EnvironmentClient

use of com.sequenceiq.environment.client.EnvironmentClient in project cloudbreak by hortonworks.

the class CleanupUtil method cleanupAllResources.

public void cleanupAllResources() {
    if (resourceFilesArePresent() && !cleanupAfterAbort) {
        cleanupDistroxes();
        cleanupSdxes();
        cleanupEnvironments();
        cleanupCredentials();
    } else {
        EnvironmentClient environmentClient = createEnvironmentClient();
        List<String> foundChildEnvironmentNames = new ArrayList<>(getChildEnvironments(environmentClient).values());
        List<String> foundEnvironmentNames = new ArrayList<>(getEnvironments(environmentClient).values());
        List<String> foundCredentialNames = getCredentials(environmentClient);
        if (!foundChildEnvironmentNames.isEmpty()) {
            LOG.info("Found child environments: '{}'", foundChildEnvironmentNames);
            deleteEnvironments(environmentClient, foundChildEnvironmentNames);
        }
        if (!foundEnvironmentNames.isEmpty()) {
            LOG.info("Found environments: '{}'", foundEnvironmentNames);
            deleteEnvironments(environmentClient, foundEnvironmentNames);
        } else {
            LOG.info("Cannot find any environment!");
        }
        if (!foundCredentialNames.isEmpty()) {
            LOG.info("Found credentials: '{}'", foundCredentialNames);
            deleteCredentials(environmentClient, foundCredentialNames);
        } else {
            LOG.info("Cannot find any credential!");
        }
    }
}
Also used : EnvironmentClient(com.sequenceiq.environment.client.EnvironmentClient) ArrayList(java.util.ArrayList)

Example 2 with EnvironmentClient

use of com.sequenceiq.environment.client.EnvironmentClient in project cloudbreak by hortonworks.

the class CleanupUtil method cleanupDistroxes.

public void cleanupDistroxes() {
    CloudbreakClient cloudbreakClient = createCloudbreakClient();
    EnvironmentClient environmentClient = createEnvironmentClient();
    List<String> foundDistroxNames = getDistroxes(environmentClient, cloudbreakClient);
    setCloudbreakClient(cloudbreakClient);
    LOG.info("Found distroxes: '{}'", foundDistroxNames);
    if (!foundDistroxNames.isEmpty()) {
        deleteResources(foundDistroxNames, "distroxName");
    } else {
        LOG.info("Cannot find any distrox");
    }
}
Also used : CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) EnvironmentClient(com.sequenceiq.environment.client.EnvironmentClient)

Example 3 with EnvironmentClient

use of com.sequenceiq.environment.client.EnvironmentClient in project cloudbreak by hortonworks.

the class CleanupUtil method cleanupCredentials.

public void cleanupCredentials() {
    EnvironmentClient environmentClient = createEnvironmentClient();
    List<String> foundCredentialNames = getCredentials(environmentClient);
    setEnvironmentClient(environmentClient);
    LOG.info("Found credentials: '{}'", foundCredentialNames);
    if (!foundCredentialNames.isEmpty()) {
        deleteResources(foundCredentialNames, "credentialName");
    } else {
        LOG.info("Cannot find any credential!");
    }
}
Also used : EnvironmentClient(com.sequenceiq.environment.client.EnvironmentClient)

Example 4 with EnvironmentClient

use of com.sequenceiq.environment.client.EnvironmentClient in project cloudbreak by hortonworks.

the class CleanupWaitUtil method checkEnvironmentDeleteFailedStatus.

/**
 * Checking the environment is in DELETE_FAILED state.
 *
 * Returns with:
 * TRUE:   DELETE_FAILED state is available.
 * FALSE:  DELETE_FAILED state is not available.
 *
 * @param environmentClient  com.sequenceiq.environment.client.EnvironmentClient
 * @param environmentName    Provided environment name
 * @return                   TRUE or FALSE based on existing DELETE_FAILED status
 */
private boolean checkEnvironmentDeleteFailedStatus(EnvironmentClient environmentClient, String environmentName) {
    try {
        EnvironmentStatus environmentStatus = environmentClient.environmentV1Endpoint().list().getResponses().stream().filter(response -> response.getName().equalsIgnoreCase(environmentName)).findFirst().map(EnvironmentBaseResponse::getEnvironmentStatus).orElse(EnvironmentStatus.ARCHIVED);
        LOG.info("{} environment actual state is: {}", environmentName, environmentStatus);
        return environmentStatus.equals(EnvironmentStatus.DELETE_FAILED);
    } catch (Exception e) {
        LOG.warn("Exception has been occurred while checking {} environment's DELETE_FAILED state: {}", environmentName, e.getMessage(), e);
        return false;
    }
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) Collectors(java.util.stream.Collectors) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) EnvironmentBaseResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse) WaitResult(com.sequenceiq.it.cloudbreak.util.WaitResult) Value(org.springframework.beans.factory.annotation.Value) SdxClient(com.sequenceiq.sdx.client.SdxClient) Component(org.springframework.stereotype.Component) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) EnvironmentClient(com.sequenceiq.environment.client.EnvironmentClient) Map(java.util.Map) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) Collections(java.util.Collections) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus)

Example 5 with EnvironmentClient

use of com.sequenceiq.environment.client.EnvironmentClient in project cloudbreak by hortonworks.

the class CleanupUtil method cleanupEnvironments.

public void cleanupEnvironments() {
    EnvironmentClient environmentClient = createEnvironmentClient();
    List<String> foundChildEnvironmentNames = new ArrayList<>(getChildEnvironments(environmentClient).values());
    List<String> foundEnvironmentNames = new ArrayList<>(getEnvironments(environmentClient).values());
    setEnvironmentClient(environmentClient);
    if (!foundChildEnvironmentNames.isEmpty()) {
        LOG.info("Found child environments: '{}'", foundChildEnvironmentNames);
        deleteResources(foundChildEnvironmentNames, "environmentName");
    }
    if (!foundEnvironmentNames.isEmpty()) {
        LOG.info("Found environments: '{}'", foundEnvironmentNames);
        deleteResources(foundEnvironmentNames, "environmentName");
    } else {
        LOG.info("Cannot find any environment!");
    }
}
Also used : EnvironmentClient(com.sequenceiq.environment.client.EnvironmentClient) ArrayList(java.util.ArrayList)

Aggregations

EnvironmentClient (com.sequenceiq.environment.client.EnvironmentClient)6 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)2 SdxClient (com.sequenceiq.sdx.client.SdxClient)2 ArrayList (java.util.ArrayList)2 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)1 EnvironmentBaseResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse)1 EnvironmentStatus (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus)1 WaitResult (com.sequenceiq.it.cloudbreak.util.WaitResult)1 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)1 SdxClusterStatusResponse (com.sequenceiq.sdx.api.model.SdxClusterStatusResponse)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Value (org.springframework.beans.factory.annotation.Value)1 Component (org.springframework.stereotype.Component)1