Search in sources :

Example 36 with CloudCredential

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);
    }
}
Also used : CheckPlatformVariantRequest(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckPlatformVariantResult(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 37 with CloudCredential

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;
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) GetInstancesStateRequest(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) GetInstancesStateResult(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 38 with CloudCredential

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));
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) OSClient(org.openstack4j.api.OSClient) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Test(org.junit.Test)

Example 39 with CloudCredential

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());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Test(org.junit.Test)

Example 40 with CloudCredential

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());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Test(org.junit.Test)

Aggregations

CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)47 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)27 Location (com.sequenceiq.cloudbreak.cloud.model.Location)18 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)9 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 Stack (com.sequenceiq.cloudbreak.domain.Stack)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)7 HashSet (java.util.HashSet)7 Compute (com.google.api.services.compute.Compute)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)5 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)5 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Strings (com.google.common.base.Strings)3