Search in sources :

Example 21 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class OpenStackUtils method getExistingSubnetCidr.

public String getExistingSubnetCidr(AuthenticatedContext authenticatedContext, NeutronNetworkView neutronNetwork) {
    if (neutronNetwork.isExistingSubnet()) {
        String subnetId = neutronNetwork.getCustomSubnetId();
        OSClient<?> osClient = openStackClient.createOSClient(authenticatedContext);
        Subnet subnet = osClient.networking().subnet().get(subnetId);
        if (subnet == null) {
            throw new CloudConnectorException("The specified subnet does not exist: " + subnetId);
        }
        return subnet.getCidr();
    }
    return null;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Subnet(org.openstack4j.model.network.Subnet)

Example 22 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class OpenStackResourceConnector method checkByResourceType.

private CloudResourceStatus checkByResourceType(AuthenticatedContext authenticatedContext, OSClient<?> client, String stackName, Collection<CloudResource> list, CloudResource resource) {
    CloudResourceStatus result = null;
    switch(resource.getType()) {
        case HEAT_STACK:
            String heatStackId = resource.getName();
            LOGGER.info("Checking OpenStack Heat stack status of: {}", stackName);
            Stack heatStack = client.heat().stacks().getDetails(stackName, heatStackId);
            result = utils.heatStatus(resource, heatStack);
            break;
        case OPENSTACK_NETWORK:
            result = checkResourceStatus(authenticatedContext, stackName, list, resource, ResourceType.OPENSTACK_NETWORK);
            break;
        case OPENSTACK_SUBNET:
            result = checkResourceStatus(authenticatedContext, stackName, list, resource, ResourceType.OPENSTACK_SUBNET);
            break;
        case OPENSTACK_ROUTER:
        case OPENSTACK_INSTANCE:
        case OPENSTACK_PORT:
        case OPENSTACK_ATTACHED_DISK:
        case OPENSTACK_SECURITY_GROUP:
        case OPENSTACK_FLOATING_IP:
            break;
        default:
            throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
    }
    return result;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Stack(org.openstack4j.model.heat.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 23 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class OpenStackImageImageImporterTest method testImportNoStatus.

@Test(expected = CloudConnectorException.class)
public void testImportNoStatus() {
    try {
        GlanceTask task = Mockito.mock(GlanceTask.class);
        when(task.getStatus()).thenReturn(null);
        when(task.getMessage()).thenReturn("USEFUL ERRROR MESSAGE");
        when(taskService.create(any())).thenReturn(task);
        underTest.importImage(osClient, "myimage");
    } catch (CloudConnectorException e) {
        Assert.assertEquals("Import of myimage did not return any status, message: USEFUL ERRROR MESSAGE", e.getMessage());
        throw e;
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GlanceTask(org.openstack4j.openstack.image.v2.domain.GlanceTask) Test(org.junit.Test)

Example 24 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class OpenStackImageVerifierTest method testFoundTwo.

@Test(expected = CloudConnectorException.class)
public void testFoundTwo() {
    try {
        GlanceImage newImage1 = new GlanceImage();
        newImage1.setId("id1");
        newImage1.setName("exist-id1");
        GlanceImage newImage2 = new GlanceImage();
        newImage2.setId("id2");
        newImage2.setName("exist-id1");
        List<GlanceImage> returnedImages = ImmutableList.of(newImage1, newImage2);
        Map<String, String> map = ImmutableMap.of("name", "exist-id1");
        doReturn(returnedImages).when(imageService).list(Mockito.eq(map));
        underTest.exist(osClient, "exist-id1");
    } catch (CloudConnectorException cce) {
        Assert.assertEquals("Multiple OpenStack images found with ids: id1, id2, image name: exist-id1", cce.getMessage());
        throw cce;
    }
}
Also used : GlanceImage(org.openstack4j.openstack.image.v2.domain.GlanceImage) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Test(org.junit.Test)

Example 25 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class TerminateStackHandler method accept.

@Override
public void accept(Event<TerminateStackRequest> terminateStackRequestEvent) {
    LOGGER.info("Received event: {}", terminateStackRequestEvent);
    TerminateStackRequest request = terminateStackRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().terminate(ac, request.getCloudStack(), request.getCloudResources());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        TerminateStackResult result;
        if (!resources.isEmpty()) {
            PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, false);
            ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(request.getCloudContext(), resourceStatus);
            if (!task.completed(statePollerResult)) {
                statePollerResult = syncPollingScheduler.schedule(task);
            }
            if (!statePollerResult.getStatus().equals(ResourceStatus.DELETED)) {
                throw new CloudConnectorException("Stack could not be terminated, Resource(s) could not be deleted on the provider side.");
            } else {
                result = new TerminateStackResult(request);
            }
        } else {
            result = new TerminateStackResult(request);
        }
        CloudCredentialStatus credentialStatus = connector.credentials().delete(ac);
        if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
            if (credentialStatus.getException() != null) {
                throw new CloudConnectorException(credentialStatus.getException());
            }
            throw new CloudConnectorException(credentialStatus.getStatusReason());
        }
        request.getResult().onNext(result);
        LOGGER.info("TerminateStackHandler finished");
        eventBus.notify(result.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), result));
    } catch (Exception e) {
        LOGGER.error("Failed to handle TerminateStackRequest", e);
        TerminateStackResult terminateStackResult = new TerminateStackResult("Stack termination failed.", e, request);
        request.getResult().onNext(terminateStackResult);
        eventBus.notify(terminateStackResult.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), terminateStackResult));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) TerminateStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackResult) TerminateStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Aggregations

CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)64 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 StorageException (com.microsoft.azure.storage.StorageException)11 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)9 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)9 AmazonServiceException (com.amazonaws.AmazonServiceException)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)8 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)7 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)6 HashMap (java.util.HashMap)6 CloudException (com.microsoft.azure.CloudException)5 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)4 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3