Search in sources :

Example 41 with CloudResourceStatus

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

the class DownscaleStackHandler method accept.

@Override
public void accept(Event<DownscaleStackRequest> downscaleStackRequestEvent) {
    LOGGER.info("Received event: {}", downscaleStackRequestEvent);
    DownscaleStackRequest request = downscaleStackRequestEvent.getData();
    DownscaleStackResult result;
    try {
        CloudContext cloudContext = request.getCloudContext();
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().downscale(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances(), request.getResourcesToScale());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        LOGGER.info("Downscale successfully finished for {}", cloudContext);
        result = new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults()));
    } catch (Exception e) {
        LOGGER.error("Failed to handle DownscaleStackRequest.", e);
        result = new DownscaleStackResult(e.getMessage(), e, request);
    }
    request.getResult().onNext(result);
    eventBus.notify(result.selector(), new Event<>(downscaleStackRequestEvent.getHeaders(), result));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 42 with CloudResourceStatus

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

the class AzureResourceConnector method launch.

@Override
public List<CloudResourceStatus> launch(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) {
    AzureCredentialView azureCredentialView = new AzureCredentialView(ac.getCloudCredential());
    String stackName = azureUtils.getStackName(ac.getCloudContext());
    String resourceGroupName = azureUtils.getResourceGroupName(ac.getCloudContext());
    AzureClient client = ac.getParameter(AzureClient.class);
    AzureStackView azureStackView = getAzureStack(azureCredentialView, ac.getCloudContext(), stack, getNumberOfAvailableIPsInSubnets(client, stack.getNetwork()));
    String customImageId = azureStorage.getCustomImageId(client, ac, stack);
    String template = azureTemplateBuilder.build(stackName, customImageId, azureCredentialView, azureStackView, ac.getCloudContext(), stack);
    String parameters = azureTemplateBuilder.buildParameters(ac.getCloudCredential(), stack.getNetwork(), stack.getImage());
    Boolean encrytionNeeded = azureStorage.isEncrytionNeeded(stack.getParameters());
    try {
        String region = ac.getCloudContext().getLocation().getRegion().value();
        if (AzureUtils.hasUnmanagedDisk(stack)) {
            Map<String, AzureDiskType> storageAccounts = azureStackView.getStorageAccounts();
            for (Entry<String, AzureDiskType> entry : storageAccounts.entrySet()) {
                azureStorage.createStorage(client, entry.getKey(), entry.getValue(), resourceGroupName, region, encrytionNeeded, stack.getTags());
            }
        }
        if (!client.templateDeploymentExists(resourceGroupName, stackName)) {
            Deployment templateDeployment = client.createTemplateDeployment(resourceGroupName, stackName, template, parameters);
            LOGGER.info("created template deployment for launch: {}", templateDeployment.exportTemplate().template());
            if (!azureUtils.isExistingNetwork(stack.getNetwork())) {
                client.collectAndSaveNetworkAndSubnet(resourceGroupName, stackName, notifier, ac.getCloudContext());
            }
        }
    } catch (CloudException e) {
        LOGGER.error("Provisioning error, cloud exception happened: ", e);
        if (e.body() != null && e.body().details() != null) {
            String details = e.body().details().stream().map(CloudError::message).collect(Collectors.joining(", "));
            throw new CloudConnectorException(String.format("Stack provisioning failed, status code %s, error message: %s, details: %s", e.body().code(), e.body().message(), details));
        } else {
            throw new CloudConnectorException(String.format("Stack provisioning failed: '%s', please go to Azure Portal for detailed message", e));
        }
    } catch (Exception e) {
        LOGGER.error("Provisioning error:", e);
        throw new CloudConnectorException(String.format("Error in provisioning stack %s: %s", stackName, e.getMessage()));
    }
    CloudResource cloudResource = new Builder().type(ResourceType.ARM_TEMPLATE).name(stackName).build();
    List<CloudResourceStatus> resources = check(ac, Collections.singletonList(cloudResource));
    LOGGER.debug("Launched resources: {}", resources);
    return resources;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) Deployment(com.microsoft.azure.management.resources.Deployment) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) CloudError(com.microsoft.azure.CloudError) CloudException(com.microsoft.azure.CloudException) ActionWentFailException(com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudException(com.microsoft.azure.CloudException) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 43 with CloudResourceStatus

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

the class StackUpscaleService method removeFailedMetadata.

private void removeFailedMetadata(Long stackId, Iterable<CloudResourceStatus> statuses, Group group) {
    Map<Long, CloudResourceStatus> failedResources = new HashMap<>();
    Set<Long> groupPrivateIds = getPrivateIds(group);
    for (CloudResourceStatus status : statuses) {
        Long privateId = status.getPrivateId();
        if (privateId != null && status.isFailed() && !failedResources.containsKey(privateId) && groupPrivateIds.contains(privateId)) {
            failedResources.put(privateId, status);
            instanceMetadataService.deleteInstanceRequest(stackId, privateId);
        }
    }
}
Also used : HashMap(java.util.HashMap) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)

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