use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method checkAndGetPlatformVariant.
public Variant checkAndGetPlatformVariant(Stack stack) {
LOGGER.debug("Get platform variant for: {}", stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
CheckPlatformVariantRequest checkPlatformVariantRequest = new CheckPlatformVariantRequest(cloudContext, cloudCredential);
eventBus.notify(checkPlatformVariantRequest.selector(), eventFactory.createEvent(checkPlatformVariantRequest));
try {
CheckPlatformVariantResult res = checkPlatformVariantRequest.await();
LOGGER.info("Platform variant result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to get platform variant", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return res.getDefaultPlatformVariant();
} catch (InterruptedException e) {
LOGGER.error("Error while getting the platform variant: " + cloudContext, e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class ServiceProviderMetadataAdapter method getState.
public InstanceSyncState getState(Stack stack, InstanceGroup instanceGroup, String instanceId) {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
InstanceGroup ig = stack.getInstanceGroupByInstanceGroupName(instanceGroup.getGroupName());
CloudInstance instance = null;
for (InstanceMetaData metaData : ig.getAllInstanceMetaData()) {
if (instanceId.equalsIgnoreCase(metaData.getInstanceId())) {
instance = metadataConverter.convert(metaData);
break;
}
}
if (instance != null) {
GetInstancesStateRequest<GetInstancesStateResult> stateRequest = new GetInstancesStateRequest<>(cloudContext, cloudCredential, Collections.singletonList(instance));
LOGGER.info("Triggering event: {}", stateRequest);
eventBus.notify(stateRequest.selector(), eventFactory.createEvent(stateRequest));
try {
GetInstancesStateResult res = stateRequest.await();
LOGGER.info("Result: {}", res);
if (res.isFailed()) {
LOGGER.error("Failed to retrieve instance state", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return transform(res.getStatuses().get(0).getStatus());
} catch (InterruptedException e) {
LOGGER.error(format("Error while retrieving instance state of: %s", cloudContext), e);
throw new OperationException(e);
}
} else {
return InstanceSyncState.DELETED;
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class OpenStackPlatformResourcesTest method testVirtualMachinesWhenTypesEmpty.
@Test
public void testVirtualMachinesWhenTypesEmpty() {
CloudCredential cloudCredential = new CloudCredential(0L, "name");
OSClient osClient = mock(OSClient.class);
String regionName = "region1";
Set<String> regionsFromOpenStack = Sets.newHashSet(regionName);
List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1"));
when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient);
when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack);
when(openStackClient.getZones(osClient, regionName)).thenReturn(availabilityZones);
when(openStackClient.getFlavors(osClient)).thenReturn(emptyList());
CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null);
verify(openStackClient, times(1)).getFlavors(osClient);
Assert.assertEquals(0, actual.getCloudVmResponses().get("zone1").size());
Assert.assertNull(actual.getDefaultCloudVmResponses().get(regionName));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class MockPlatformResourcesTest method getDefaultRegionWhenNoDefaultFoundForMockProviderThenShouldReturnWithTheFirstElement.
@Test
public void getDefaultRegionWhenNoDefaultFoundForMockProviderThenShouldReturnWithTheFirstElement() throws Exception {
ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-1");
underTest.init();
CloudRegions regions = underTest.regions(new CloudCredential(1L, "mock"), region("mock"), new HashMap<>());
Assert.assertEquals("USA", regions.getDefaultRegion());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class MockPlatformResourcesTest method getDefaultRegionWhenDefaultFoundForMockProviderThenShouldReturnWithDefaultElement.
@Test
public void getDefaultRegionWhenDefaultFoundForMockProviderThenShouldReturnWithDefaultElement() throws Exception {
ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-1,MOCK:Europe");
underTest.init();
CloudRegions regions = underTest.regions(new CloudCredential(1L, "mock"), region("mock"), new HashMap<>());
Assert.assertEquals("Europe", regions.getDefaultRegion());
}
Aggregations