Search in sources :

Example 21 with VolumeSetAttributes

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

the class AzureVolumeResourceBuilder method delete.

@Override
@Retryable(value = RuntimeException.class, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public CloudResource delete(AzureContext context, AuthenticatedContext auth, CloudResource resource) throws PreserveResourceException {
    LOGGER.info("Delete the disks from the instances if they are not reattached. {}", resource);
    VolumeSetAttributes volumeSetAttributes = getVolumeSetAttributes(resource);
    List<CloudResourceStatus> cloudResourceStatuses = checkResources(ResourceType.AZURE_VOLUMESET, context, auth, List.of(resource));
    boolean anyDeleted = cloudResourceStatuses.stream().map(CloudResourceStatus::getStatus).anyMatch(ResourceStatus.DELETED::equals);
    preserveVolumeIfDoNotDeleteOnTermination(auth, resource, volumeSetAttributes, anyDeleted);
    LOGGER.info("Resource {} will be deleted.", resource.getName());
    AzureClient client = getAzureClient(auth);
    List<CloudResourceStatus> removableDisks = cloudResourceStatuses.stream().filter(cloudResourceStatus -> ResourceStatus.CREATED.equals(cloudResourceStatus.getStatus()) || (ResourceStatus.ATTACHED.equals(cloudResourceStatus.getStatus()) && volumeSetAttributes.getDeleteOnTermination())).collect(toList());
    deleteVolumes(client, removableDisks);
    return null;
}
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) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Retryable(org.springframework.retry.annotation.Retryable)

Example 22 with VolumeSetAttributes

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

the class GcpAttachedDiskResourceBuilderTest method setUpBuild.

@BeforeEach
void setUpBuild() throws Exception {
    privateCrn = "crn";
    CloudContext cloudContext = CloudContext.Builder.builder().withId(privateId).withName("testname").withCrn("crn").withPlatform("GCP").withWorkspaceId(WORKSPACE_ID).build();
    CloudCredential cloudCredential = new CloudCredential(privateCrn, "credentialname", "account");
    cloudCredential.putParameter("projectId", "projectId");
    cloudInstance = new CloudInstance(instanceId, new InstanceTemplate("flavor", "group", 1L, new ArrayList<>(), InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 1L, "img", TemporaryStorage.ATTACHED_VOLUMES, 0L), new InstanceAuthentication("pub", "pub", "cb"), "subnet1", "az1");
    Location location = Location.location(Region.region("region"), AvailabilityZone.availabilityZone("az"));
    context = new GcpContext(cloudContext.getName(), location, "projectId", "serviceAccountId", compute, false, 30, false);
    List<CloudResource> networkResources = Collections.singletonList(new Builder().type(ResourceType.GCP_NETWORK).name("network-test").build());
    context.addNetworkResources(networkResources);
    privateId = 1L;
    name = "master";
    flavor = "m1.medium";
    instanceId = "SOME_ID";
    auth = new AuthenticatedContext(cloudContext, cloudCredential);
    params = Map.of();
    volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1, CloudVolumeUsageType.GENERAL), new Volume("/hadoop/fs2", "HDD", 1, CloudVolumeUsageType.GENERAL));
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    security = new Security(rules, emptyList());
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    InstanceTemplate instanceTemplate = new InstanceTemplate(flavor, name, privateId, volumes, InstanceStatus.CREATE_REQUESTED, params, 0L, "cb-centos66-amb200-2015-05-25", TemporaryStorage.ATTACHED_VOLUMES, 0L);
    CloudInstance cloudInstance = new CloudInstance(instanceId, instanceTemplate, instanceAuthentication, "subnet-1", "az1");
    group = new Group(name, InstanceGroupType.CORE, Collections.singletonList(cloudInstance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), 50, Optional.empty(), createGroupNetwork(), emptyMap());
    List<VolumeSetAttributes.Volume> volumes = new ArrayList<>();
    volumes.add(new VolumeSetAttributes.Volume("1234", "noop", 0, "eph", CloudVolumeUsageType.GENERAL));
    VolumeSetAttributes attributes = new VolumeSetAttributes("Ireland", true, "", volumes, 0, "eph");
    Map<String, Object> params = new HashMap<>();
    params.put(CloudResource.ATTRIBUTES, attributes);
    buildableResource = List.of(CloudResource.builder().type(ResourceType.GCP_DISK).status(CommonStatus.REQUESTED).name("disk").params(params).build());
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
    Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "redhat6", "", "default", "default-id", new HashMap<>());
    cloudStack = new CloudStack(Collections.emptyList(), null, image, emptyMap(), emptyMap(), null, null, null, null, null);
    when(intermediateBuilderExecutor.submit(any(Callable.class))).thenAnswer(invocation -> {
        Callable<Void> callable = invocation.getArgument(0);
        return new MockFuture(callable);
    });
    operation = new Operation();
    operation.setName("operation");
    operation.setHttpErrorStatusCode(null);
    when(compute.disks()).thenReturn(disks);
    when(disks.insert(anyString(), anyString(), any(Disk.class))).thenReturn(insert);
    when(insert.execute()).thenReturn(operation);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) HashMap(java.util.HashMap) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) ArrayList(java.util.ArrayList) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Operation(com.google.api.services.compute.model.Operation) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Callable(java.util.concurrent.Callable) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) GcpContext(com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext) Disk(com.google.api.services.compute.model.Disk) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Location(com.sequenceiq.cloudbreak.cloud.model.Location) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with VolumeSetAttributes

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

the class GcpResourceConnectorTest method cloudResource.

private CloudResource cloudResource(String name, ResourceType resourceType) {
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 1, "type");
    volumeSetAttributes.setDiscoveryFQDN("fqdn");
    return CloudResource.builder().type(resourceType).name(name).group("master").status(CommonStatus.REQUESTED).params(Map.of(CloudResource.ATTRIBUTES, volumeSetAttributes)).build();
}
Also used : VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 24 with VolumeSetAttributes

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

the class StackUtilTest method getVolumeSetResource.

private Resource getVolumeSetResource(String instanceID) {
    Resource resource = new Resource();
    resource.setResourceType(ResourceType.AZURE_VOLUMESET);
    resource.setInstanceId(instanceID);
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes.Builder().build();
    resource.setAttributes(new Json(volumeSetAttributes));
    return resource;
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) Json(com.sequenceiq.cloudbreak.common.json.Json) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 25 with VolumeSetAttributes

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

the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovableWithRepairAndReplication.

@Test
public void testVerifyNodesAreRemovableWithRepairAndReplication() throws ApiException {
    // GIVEN
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 50, "vt");
    Stack stack = createTestStack(volumeSetAttributes);
    Cluster cluster = new Cluster();
    stack.setCluster(cluster);
    Set<HostGroup> hostGroups = createTestHostGroups(2, 5);
    cluster.setHostGroups(hostGroups);
    // Multimap<Long, InstanceMetaData> hostGroupWithInstances = createTestHostGroupWithInstances();
    ApiServiceConfig apiServiceConfig = createApiServiceConfigWithReplication("3", true);
    ApiHostTemplateList hostTemplates = createHostTemplatesWithDataNodes(hostGroups.stream().findFirst().get().getName());
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
    when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
    when(resourceAttributeUtil.getTypedAttributes(stack.getDiskResources().get(0), VolumeSetAttributes.class)).thenReturn(Optional.of(volumeSetAttributes));
    when(clouderaManagerApiFactory.getServicesResourceApi(Mockito.any(ApiClient.class))).thenReturn(servicesResourceApi);
    when(servicesResourceApi.readServiceConfig(stack.getName(), "hdfs", "full")).thenReturn(apiServiceConfig);
    when(clouderaManagerApiFactory.getHostsResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostsResourceApi);
    when(hostsResourceApi.readHosts(eq(null), eq(null), anyString())).thenReturn(apiHostList);
    when(apiHostList.getItems()).thenReturn(List.of());
    // WHEN
    HostGroup firstHostGroup = hostGroups.iterator().next();
    Set<InstanceMetaData> firstHostGroupInstances = firstHostGroup.getInstanceGroup().getInstanceMetaDataSet();
    Set<InstanceMetaData> removableInstances = firstHostGroupInstances.stream().limit(5).collect(Collectors.toSet());
    underTest.verifyNodesAreRemovable(stack, removableInstances, new ApiClient());
// THEN no exception
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Test(org.junit.Test)

Aggregations

VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)49 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)27 ArrayList (java.util.ArrayList)26 Test (org.junit.jupiter.api.Test)18 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)16 List (java.util.List)16 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)14 ResourceType (com.sequenceiq.common.api.type.ResourceType)14 Group (com.sequenceiq.cloudbreak.cloud.model.Group)12 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)12 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)12 CommonStatus (com.sequenceiq.common.api.type.CommonStatus)12 Collectors (java.util.stream.Collectors)12 Optional (java.util.Optional)11 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)10 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)10 Resource (com.sequenceiq.cloudbreak.domain.Resource)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)10 Inject (javax.inject.Inject)10 Logger (org.slf4j.Logger)10