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