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;
}
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);
}
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();
}
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;
}
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
}
Aggregations