use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class StackCreationService method setInstanceStoreCount.
public void setInstanceStoreCount(StackContext stackContext) {
Stack stack = stackContext.getStack();
CloudConnector<Object> connector = cloudPlatformConnectors.get(stackContext.getCloudContext().getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(stackContext.getCloudContext(), stackContext.getCloudCredential());
List<String> instanceTypes = stack.getInstanceGroups().stream().map(InstanceGroup::getTemplate).filter(Objects::nonNull).map(Template::getInstanceType).filter(Objects::nonNull).collect(Collectors.toList());
InstanceStoreMetadata instanceStoreMetadata = connector.metadata().collectInstanceStorageCount(ac, instanceTypes);
for (InstanceGroup ig : stack.getInstanceGroups()) {
Template template = ig.getTemplate();
if (template != null) {
Integer instanceStorageCount = instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled(template.getInstanceType());
if (ephemeralVolumeChecker.instanceGroupContainsOnlyDatabaseAndEphemeralVolumes(ig)) {
LOGGER.debug("Instance storage was already requested. Setting temporary storage in template to: {}. " + "Group name: {}, Template id: {}, instance type: {}", TemporaryStorage.EPHEMERAL_VOLUMES_ONLY.name(), ig.getGroupName(), template.getId(), template.getInstanceType());
template.setTemporaryStorage(TemporaryStorage.EPHEMERAL_VOLUMES_ONLY);
} else if (instanceStorageCount > 0 && stack.getType().equals(StackType.WORKLOAD)) {
LOGGER.debug("The host group's instance type has ephemeral volumes. Setting temporary storage in template to: {}. " + "Group name: {}, Template id: {}, instance type: {}", TemporaryStorage.EPHEMERAL_VOLUMES.name(), ig.getGroupName(), template.getId(), template.getInstanceType());
template.setTemporaryStorage(TemporaryStorage.EPHEMERAL_VOLUMES);
}
LOGGER.debug("Setting instance storage count in template. " + "Group name: {}, Template id: {}, instance type: {}", ig.getGroupName(), template.getId(), template.getInstanceType());
template.setInstanceStorageCount(instanceStorageCount);
templateService.savePure(template);
}
}
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class StackCreationServiceTest method setUp.
@BeforeEach
void setUp() {
Whitebox.setInternalState(underTest, "ephemeralVolumeChecker", new InstanceGroupEphemeralVolumeChecker());
CloudConnector<Object> cloudConnector = Mockito.mock(CloudConnector.class);
when(cloudPlatformConnectors.get(any())).thenReturn(cloudConnector);
MetadataCollector metadataCollector = Mockito.mock(MetadataCollector.class);
when(cloudConnector.metadata()).thenReturn(metadataCollector);
Authenticator authenticator = Mockito.mock(Authenticator.class);
when(cloudConnector.authentication()).thenReturn(authenticator);
InstanceStoreMetadata instanceStoreMetadata = getInstanceStoreMetadata();
when(metadataCollector.collectInstanceStorageCount(any(), any())).thenReturn(instanceStoreMetadata);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class AzurePlatformResourcesTest method collectInstanceStorageCountTest.
@Test
void collectInstanceStorageCountTest() {
Region region = Region.region("us-west-1");
CloudContext cloudContext = new CloudContext.Builder().withLocation(Location.location(region, availabilityZone("us-west-1"))).build();
AuthenticatedContext ac = new AuthenticatedContext(cloudContext, cloudCredential);
Set<VirtualMachineSize> virtualMachineSizes = new HashSet<>();
virtualMachineSizes.add(createVirtualMachineSize("Standard_D8_v3", 20000));
when(azureClient.getVmTypes(region.value())).thenReturn(virtualMachineSizes);
InstanceStoreMetadata instanceStoreMetadata = underTest.collectInstanceStorageCount(ac, Collections.singletonList("Standard_D8_v3"));
assertEquals(1, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("Standard_D8_v3"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("unsupported"));
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class AwsPlatformResources method collectInstanceStorageCount.
public InstanceStoreMetadata collectInstanceStorageCount(AuthenticatedContext ac, List<String> instanceTypes, List<String> entitlements) {
Location location = ac.getCloudContext().getLocation();
try {
String accountId = ac.getCloudContext().getAccountId();
ExtendedCloudCredential extendedCloudCredential = new ExtendedCloudCredential(ac.getCloudCredential(), ac.getCloudContext().getPlatform().value(), "", ac.getCloudContext().getCrn(), accountId, entitlements);
CloudVmTypes cloudVmTypes = virtualMachines(extendedCloudCredential, location.getRegion(), Map.of());
Map<String, Set<VmType>> cloudVmResponses = cloudVmTypes.getCloudVmResponses();
Map<String, VolumeParameterConfig> instanceTypeToInstanceStorageMap = cloudVmResponses.getOrDefault(location.getAvailabilityZone().value(), Set.of()).stream().filter(vmType -> instanceTypes.contains(vmType.value())).filter(vmType -> Objects.nonNull(vmType.getMetaData().getEphemeralConfig())).collect(Collectors.toMap(VmType::value, vmType -> vmType.getMetaData().getEphemeralConfig()));
return new InstanceStoreMetadata(instanceTypeToInstanceStorageMap);
} catch (Exception e) {
LOGGER.warn("Failed to get vm type data: {}", instanceTypes, e);
throw new CloudConnectorException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class StackCreationServiceTest method getInstanceStoreMetadata.
private InstanceStoreMetadata getInstanceStoreMetadata() {
InstanceStoreMetadata instanceStoreMetadata = new InstanceStoreMetadata();
VolumeParameterConfig instanceStorageConfig = new VolumeParameterConfig(VolumeParameterType.EPHEMERAL, 100, 100, 2, 2);
instanceStoreMetadata.getInstaceStoreConfigMap().put("vm.type", instanceStorageConfig);
return instanceStoreMetadata;
}
Aggregations