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