Search in sources :

Example 21 with CloudResourceStatus

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

the class PollResourcesStateTask method doCall.

@Override
protected ResourcesStatePollerResult doCall() {
    List<CloudResourceStatus> results = resourceConnector.check(getAuthenticatedContext(), cloudResource);
    CloudResourceStatus status = ResourceStatusLists.aggregate(results);
    return new ResourcesStatePollerResult(getAuthenticatedContext().getCloudContext(), status.getStatus(), status.getStatusReason(), results);
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)

Example 22 with CloudResourceStatus

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

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

the class StackCreationService method updateNodeCount.

private void updateNodeCount(Long stackId, Iterable<Group> originalGroups, Iterable<CloudResourceStatus> statuses) {
    for (Group group : originalGroups) {
        int nodeCount = group.getInstancesSize();
        List<CloudResourceStatus> failedResources = removeFailedMetadata(stackId, statuses, group);
        if (!failedResources.isEmpty()) {
            int failedCount = failedResources.size();
            InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stackId, group.getName());
            instanceGroup.setNodeCount(nodeCount - failedCount);
            instanceGroupRepository.save(instanceGroup);
            flowMessageService.fireEventAndLog(stackId, Msg.STACK_INFRASTRUCTURE_ROLLBACK_MESSAGE, UPDATE_IN_PROGRESS.name(), failedCount, group.getName(), failedResources.get(0).getStatusReason());
        }
    }
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 24 with CloudResourceStatus

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

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

the class StackCreationService method provisioningFinished.

public Stack provisioningFinished(StackContext context, LaunchStackResult result, Map<Object, Object> variables) {
    Date startDate = getStartDateIfExist(variables);
    Stack stack = context.getStack();
    validateResourceResults(context.getCloudContext(), result);
    List<CloudResourceStatus> results = result.getResults();
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.METADATA_COLLECTION, "Metadata collection");
    updateNodeCount(stack.getId(), context.getCloudStack().getGroups(), results);
    flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_INFRASTRUCTURE_TIME, UPDATE_IN_PROGRESS.name(), calculateStackCreationTime(startDate));
    return stackService.getByIdWithLists(stack.getId());
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Date(java.util.Date) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)43 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)29 ArrayList (java.util.ArrayList)18 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 List (java.util.List)11 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)5 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)5 Group (com.sequenceiq.cloudbreak.cloud.model.Group)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 NetworkResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder)4 CloudException (com.microsoft.azure.CloudException)3 Deployment (com.microsoft.azure.management.resources.Deployment)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 ComputeResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder)3 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)3