Search in sources :

Example 31 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class AbstractResourceConnector method update.

@Override
public List<CloudResourceStatus> update(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), resources, true);
    // group
    List<CloudResource> groupResources = groupResourceService.getGroupResources(platform, resources);
    List<CloudResourceStatus> groupStatuses = groupResourceService.update(context, auth, stack.getNetwork(), stack.getCloudSecurity(), groupResources);
    // network
    List<CloudResource> networkResources = networkResourceService.getNetworkResources(platform, resources);
    List<CloudResourceStatus> networkStatuses = networkResourceService.update(context, auth, stack.getNetwork(), stack.getCloudSecurity(), networkResources);
    groupStatuses.addAll(networkStatuses);
    return groupStatuses;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 32 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class CloudFailureHandler method handleExceptions.

private void handleExceptions(AuthenticatedContext auth, List<CloudResourceStatus> cloudResourceStatuses, Group group, ResourceBuilderContext ctx, ResourceBuilders resourceBuilders, Collection<Long> ids, Boolean upscale) {
    List<CloudResource> resources = new ArrayList<>(cloudResourceStatuses.size());
    for (CloudResourceStatus exception : cloudResourceStatuses) {
        if (ResourceStatus.FAILED.equals(exception.getStatus()) || ids.contains(exception.getPrivateId())) {
            LOGGER.error("Failed to create instance: " + exception.getStatusReason());
            resources.add(exception.getCloudResource());
        }
    }
    if (!resources.isEmpty()) {
        LOGGER.info("Resource list not empty so rollback will start.Resource list size is: " + resources.size());
        doRollbackAndDecreaseNodeCount(auth, cloudResourceStatuses, ids, group, ctx, resourceBuilders, upscale);
    }
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 33 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class StackDownscaleActions method stackDownscaleAction.

@Bean(name = "DOWNSCALE_STATE")
public Action<?, ?> stackDownscaleAction() {
    return new AbstractStackDownscaleAction<DownscaleStackCollectResourcesResult>(DownscaleStackCollectResourcesResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, DownscaleStackCollectResourcesResult payload, Map<Object, Object> variables) {
            Selectable request = new DownscaleStackRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), (List<CloudResource>) variables.get(RESOURCES), (List<CloudInstance>) variables.get(INSTANCES), payload.getResourcesToScale());
            sendEvent(context.getFlowId(), request);
        }
    };
}
Also used : Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) DownscaleStackCollectResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 34 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.

the class YarnResourceConnector method check.

@Override
public List<CloudResourceStatus> check(AuthenticatedContext authenticatedContext, List<CloudResource> resources) {
    YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
    List<CloudResourceStatus> result = new ArrayList<>();
    for (CloudResource resource : resources) {
        switch(resource.getType()) {
            case YARN_APPLICATION:
                LOGGER.info("Checking Yarn application status of: {}", resource.getName());
                try {
                    ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
                    applicationDetailRequest.setName(resource.getName());
                    ResponseContext responseContext = yarnClient.getApplicationDetail(applicationDetailRequest);
                    if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
                        ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
                        result.add(new CloudResourceStatus(resource, YarnApplicationStatus.mapResourceStatus(applicationDetailResponse.getState())));
                    } else if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_NOT_FOUND) {
                        result.add(new CloudResourceStatus(resource, ResourceStatus.DELETED, "Yarn application has been killed."));
                    } else if (responseContext.getResponseError() != null) {
                        throw new CloudConnectorException(String.format("Yarn Application status check failed: HttpStatusCode: %d, Error: %s", responseContext.getStatusCode(), responseContext.getResponseError().getDiagnostics()));
                    } else {
                        throw new CloudConnectorException(String.format("Yarn Application status check failed: Invalid HttpStatusCode: %d", responseContext.getStatusCode()));
                    }
                } catch (MalformedURLException | RuntimeException e) {
                    throw new CloudConnectorException(String.format("Invalid resource exception: %s", e.getMessage()), e);
                }
                break;
            default:
                throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
        }
    }
    return result;
}
Also used : ApplicationDetailResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationDetailResponse) MalformedURLException(java.net.MalformedURLException) ApplicationDetailRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.ApplicationDetailRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResponseContext(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient)

Example 35 with CloudResource

use of com.sequenceiq.cloudbreak.cloud.model.CloudResource 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

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)79 ArrayList (java.util.ArrayList)33 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)29 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)20 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)17 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)16 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)13 List (java.util.List)11 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)8 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Group (com.sequenceiq.cloudbreak.cloud.model.Group)7 Operation (com.google.api.services.compute.model.Operation)6 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)6 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)6 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)6 Map (java.util.Map)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5