Search in sources :

Example 81 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class CheckImageHandler method accept.

@Override
public void accept(Event<CheckImageRequest> event) {
    LOGGER.info("Received event: {}", event);
    CheckImageRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        Image image = request.getImage();
        CloudStack stack = request.getStack();
        ImageStatusResult progress = connector.setup().checkImageStatus(auth, stack, image);
        CheckImageResult imageResult = new CheckImageResult(request, progress.getImageStatus(), progress.getStatusProgressValue());
        request.getResult().onNext(imageResult);
        LOGGER.info("Provision setup finished for {}", cloudContext);
    } catch (RuntimeException e) {
        CheckImageResult failure = new CheckImageResult(e, request, ImageStatus.CREATE_FAILED);
        request.getResult().onNext(failure);
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Example 82 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class CreateCredentialHandler method accept.

@Override
public void accept(Event<CreateCredentialRequest> credentialRequestEvent) {
    LOGGER.info("Received event: {}", credentialRequestEvent);
    CreateCredentialRequest request = credentialRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        CloudCredentialStatus credentialStatus = connector.credentials().create(ac);
        if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
            if (credentialStatus.getException() != null) {
                throw new CloudConnectorException(credentialStatus.getException());
            }
            throw new CloudConnectorException(credentialStatus.getStatusReason());
        }
        CreateCredentialResult result = new CreateCredentialResult(request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(credentialRequestEvent.getHeaders(), result));
        LOGGER.info("Creating credential successfully finished for {}", cloudContext);
    } catch (RuntimeException e) {
        CreateCredentialResult failure = new CreateCredentialResult(e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(credentialRequestEvent.getHeaders(), failure));
    }
}
Also used : CreateCredentialRequest(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) CreateCredentialResult(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult)

Example 83 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class OpenStackAttachedDiskResourceBuilder method checkStatus.

@Override
protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
    CloudContext cloudContext = auth.getCloudContext();
    OSClient<?> osClient = createOSClient(auth);
    Volume osVolume = osClient.blockStorage().volumes().get(resource.getReference());
    if (osVolume != null && context.isBuild()) {
        Status volumeStatus = osVolume.getStatus();
        if (Status.ERROR == volumeStatus || Status.ERROR_DELETING == volumeStatus || Status.ERROR_RESTORING == osVolume.getStatus()) {
            throw new OpenStackResourceException("Volume in failed state", resource.getType(), resource.getName(), cloudContext.getId(), volumeStatus.name());
        }
        return volumeStatus == Status.AVAILABLE;
    } else {
        return osVolume == null && !context.isBuild();
    }
}
Also used : Status(org.openstack4j.model.storage.block.Volume.Status) Volume(org.openstack4j.model.storage.block.Volume) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)

Example 84 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AwsMetaDataCollectorTest method authenticatedContext.

private AuthenticatedContext authenticatedContext() {
    Location location = Location.location(Region.region("region"), AvailabilityZone.availabilityZone("az"));
    CloudContext cloudContext = new CloudContext(5L, "name", "platform", "owner", "variant", location);
    CloudCredential cc = new CloudCredential(1L, null, null);
    return new AuthenticatedContext(cloudContext, cc);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 85 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit24Vpc.

@Test
public void testFindNonOverLappingCIDRWit24Vpc() {
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    Map<String, Object> networkParameters = new HashMap<>();
    networkParameters.put("vpcId", "vpc-12345678");
    networkParameters.put("internetGatewayId", "igw-12345678");
    Network network = new Network(new Subnet(null), networkParameters);
    CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudContext cloudContext = mock(CloudContext.class);
    Location location = mock(Location.class);
    Vpc vpc = mock(Vpc.class);
    DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
    AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
    com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
    DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    when(cloudContext.getLocation()).thenReturn(location);
    when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
    when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
    when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
    when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
    when(vpc.getCidrBlock()).thenReturn("10.0.0.0/24");
    when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
    when(subnetsResult.getSubnets()).thenReturn(singletonList(subnet1));
    when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/24");
    thrown.expect(CloudConnectorException.class);
    thrown.expectMessage("The selected VPC has to be in a bigger CIDR range than /24");
    underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
}
Also used : DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Vpc(com.amazonaws.services.ec2.model.Vpc) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Test(org.junit.Test)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)100 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)43 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)34 Test (org.junit.Test)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)33 HashMap (java.util.HashMap)33 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)32 Location (com.sequenceiq.cloudbreak.cloud.model.Location)31 Network (com.sequenceiq.cloudbreak.cloud.model.Network)31 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)31 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)25 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)15 ArrayList (java.util.ArrayList)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14