Search in sources :

Example 1 with DeleteApplicationRequest

use of com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.DeleteApplicationRequest in project cloudbreak by hortonworks.

the class YarnResourceConnector method terminate.

@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> cloudResources) {
    for (CloudResource resource : cloudResources) {
        switch(resource.getType()) {
            case YARN_APPLICATION:
                YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
                String yarnApplicationName = resource.getName();
                String stackName = authenticatedContext.getCloudContext().getName();
                LOGGER.info("Terminate stack: {}", stackName);
                try {
                    DeleteApplicationRequest deleteApplicationRequest = new DeleteApplicationRequest();
                    deleteApplicationRequest.setName(yarnApplicationName);
                    yarnClient.deleteApplication(deleteApplicationRequest);
                    LOGGER.info("Yarn Applicatin has been deleted");
                } catch (MalformedURLException | YarnClientException e) {
                    throw new CloudConnectorException("Stack cannot be deleted", e);
                }
                break;
            default:
                throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
        }
    }
    return check(authenticatedContext, cloudResources);
}
Also used : MalformedURLException(java.net.MalformedURLException) YarnClientException(com.sequenceiq.cloudbreak.cloud.yarn.client.exception.YarnClientException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DeleteApplicationRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.DeleteApplicationRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient)

Aggregations

CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 YarnClient (com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient)1 YarnClientException (com.sequenceiq.cloudbreak.cloud.yarn.client.exception.YarnClientException)1 DeleteApplicationRequest (com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.DeleteApplicationRequest)1 MalformedURLException (java.net.MalformedURLException)1