Search in sources :

Example 6 with ResourceType

use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.

the class AzureVolumeResourceBuilder method checkResources.

@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AzureContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    AzureClient client = getAzureClient(auth);
    List<CloudResource> volumeResources = StreamSupport.stream(resources.spliterator(), false).filter(r -> r.getType().equals(resourceType())).collect(toList());
    CloudResource resourceGroup = context.getNetworkResources().stream().filter(r -> r.getType().equals(ResourceType.AZURE_RESOURCE_GROUP)).findFirst().orElseThrow(() -> new AzureResourceException("Resource group resource not found"));
    String resourceGroupName = resourceGroup.getName();
    PagedList<Disk> existingDisks = client.listDisksByResourceGroup(resourceGroupName);
    ResourceStatus volumeSetStatus = getResourceStatus(existingDisks, volumeResources);
    return volumeResources.stream().map(resource -> new CloudResourceStatus(resource, volumeSetStatus)).collect(toList());
}
Also used : AzureContext(com.sequenceiq.cloudbreak.cloud.azure.context.AzureContext) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZoneId(com.microsoft.azure.management.resources.fluentcore.arm.AvailabilityZoneId) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) DeviceNameGenerator(com.sequenceiq.cloudbreak.util.DeviceNameGenerator) Future(java.util.concurrent.Future) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) AzureInstanceView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureInstanceView) AzureUtils(com.sequenceiq.cloudbreak.cloud.azure.AzureUtils) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) AzureResourceGroupMetadataProvider(com.sequenceiq.cloudbreak.cloud.azure.AzureResourceGroupMetadataProvider) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AzureDiskType(com.sequenceiq.cloudbreak.cloud.azure.AzureDiskType) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) Objects(java.util.Objects) Disk(com.microsoft.azure.management.compute.Disk) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AzureResourceNameService(com.sequenceiq.cloudbreak.cloud.azure.service.AzureResourceNameService) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) PagedList(com.microsoft.azure.PagedList) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StreamSupport(java.util.stream.StreamSupport) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Retryable(org.springframework.retry.annotation.Retryable) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) PreserveResourceException(com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException) Collections(java.util.Collections) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Disk(com.microsoft.azure.management.compute.Disk)

Example 7 with ResourceType

use of com.sequenceiq.common.api.type.ResourceType 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) {
        ResourceType resourceType = resource.getType();
        if (resourceType == YARN_APPLICATION || resourceType == YARN_LOAD_BALANCER) {
            LOGGER.debug("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);
            }
        } else {
            throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
        }
    }
    return result;
}
Also used : MalformedURLException(java.net.MalformedURLException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) ResourceType(com.sequenceiq.common.api.type.ResourceType) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient) ApplicationDetailResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationDetailResponse) ApplicationDetailRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.ApplicationDetailRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResponseContext(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 8 with ResourceType

use of com.sequenceiq.common.api.type.ResourceType 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) {
        ResourceType resourceType = resource.getType();
        if (resourceType == YARN_APPLICATION || resourceType == YARN_LOAD_BALANCER) {
            YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
            String yarnApplicationName = resource.getName();
            String stackName = authenticatedContext.getCloudContext().getName();
            LOGGER.debug("Terminate stack: {}", stackName);
            try {
                DeleteApplicationRequest deleteApplicationRequest = new DeleteApplicationRequest();
                deleteApplicationRequest.setName(yarnApplicationName);
                yarnClient.deleteApplication(deleteApplicationRequest);
                LOGGER.info("Yarn Application has been deleted");
            } catch (MalformedURLException | YarnClientException e) {
                throw new CloudConnectorException("Stack cannot be deleted", e);
            }
        } else {
            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) ResourceType(com.sequenceiq.common.api.type.ResourceType) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient)

Example 9 with ResourceType

use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.

the class CloudFailureHandler method doRollback.

private void doRollback(AuthenticatedContext auth, List<CloudResourceStatus> statuses, Collection<Long> rollbackIds, Group group, ResourceBuilderContext ctx, ResourceBuilders resourceBuilders, Boolean upscale) {
    Variant variant = auth.getCloudContext().getVariant();
    LOGGER.info("Rollback resources for the following private ids: {}", rollbackIds);
    if (getRemovableInstanceTemplates(group, rollbackIds).size() <= 0 && !upscale) {
        LOGGER.info("InstanceGroup node count lower than 1 which is incorrect so error will be thrown");
        throwError(statuses);
    } else {
        Map<ResourceType, ComputeResourceBuilder<ResourceBuilderContext>> resourceBuilderMap = getResourceBuilderMap(resourceBuilders, variant);
        for (CloudResourceStatus cloudResourceStatus : statuses) {
            try {
                if (rollbackIds.contains(cloudResourceStatus.getPrivateId())) {
                    ComputeResourceBuilder<ResourceBuilderContext> resourceBuilderForType = resourceBuilderMap.get(cloudResourceStatus.getCloudResource().getType());
                    deleteResource(auth, ctx, resourceBuilderForType, cloudResourceStatus);
                }
            } catch (Exception e) {
                LOGGER.warn("Resource can not be deleted. Reason: " + e.getMessage(), e);
            }
        }
    }
}
Also used : Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) ResourceType(com.sequenceiq.common.api.type.ResourceType) RolledbackResourcesException(com.sequenceiq.cloudbreak.cloud.exception.RolledbackResourcesException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with ResourceType

use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.

the class AwsRdsLaunchServiceTest method checkOutputResourceInternal.

private void checkOutputResourceInternal(List<CloudResourceStatus> cloudResourceStatuses, ResourceType type, String nameExpected, boolean existenceExpected) {
    Optional<CloudResourceStatus> cloudResourceStatusOptional = cloudResourceStatuses.stream().filter(resource -> resource.getCloudResource().getType() == type).findFirst();
    if (existenceExpected) {
        assertThat(cloudResourceStatusOptional.isPresent()).isTrue();
        CloudResourceStatus cloudResourceStatus = cloudResourceStatusOptional.get();
        assertThat(cloudResourceStatus.getStatus()).isEqualTo(ResourceStatus.CREATED);
        assertThat(cloudResourceStatus.getCloudResource().getName()).isEqualTo(nameExpected);
    } else {
        assertThat(cloudResourceStatusOptional.isEmpty()).isTrue();
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudFormationTemplateBuilder(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder) RDSModelContext(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CREATED_DB_SUBNET_GROUP(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsRdsLaunchService.CREATED_DB_SUBNET_GROUP) Waiter(com.amazonaws.waiters.Waiter) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudFormationStackUtil(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) List(java.util.List) Optional(java.util.Optional) CREATED_DB_INSTANCE(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsRdsLaunchService.CREATED_DB_INSTANCE) OutboundInternetTraffic(com.sequenceiq.common.api.type.OutboundInternetTraffic) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) CREATED_DB_PARAMETER_GROUP(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsRdsLaunchService.CREATED_DB_PARAMETER_GROUP) HOSTNAME(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsRdsLaunchService.HOSTNAME) Captor(org.mockito.Captor) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) ArgumentCaptor(org.mockito.ArgumentCaptor) Map.entry(java.util.Map.entry) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) InjectMocks(org.mockito.InjectMocks) Security(com.sequenceiq.cloudbreak.cloud.model.Security) ResourceType(com.sequenceiq.common.api.type.ResourceType) AwsStackRequestHelper(com.sequenceiq.cloudbreak.cloud.aws.AwsStackRequestHelper) AwsCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) PORT(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsRdsLaunchService.PORT) Mockito.when(org.mockito.Mockito.when) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) Collections(java.util.Collections) DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)

Aggregations

ResourceType (com.sequenceiq.common.api.type.ResourceType)12 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)9 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)9 CommonStatus (com.sequenceiq.common.api.type.CommonStatus)7 ArrayList (java.util.ArrayList)7 Collections (java.util.Collections)7 List (java.util.List)7 Map (java.util.Map)7 Optional (java.util.Optional)7 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)6 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)6 Group (com.sequenceiq.cloudbreak.cloud.model.Group)6 Collectors (java.util.stream.Collectors)6 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)5 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)5 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)5 Image (com.sequenceiq.cloudbreak.cloud.model.Image)5 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)5 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)5 VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)5