use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackImageImporter method evaluateTaskStatus.
private void evaluateTaskStatus(Task task, String name) {
if (task != null) {
TaskStatus status = task.getStatus();
LOGGER.info("Task status: {}", status);
if (status == null) {
throw new CloudConnectorException(String.format("Import of %s did not return any status, message: %s", name, task.getMessage()));
} else if (status == TaskStatus.FAILURE || status == TaskStatus.UNKNOWN) {
throw new CloudConnectorException(String.format("Import of %s failed with status: %s, message: %s", name, status, task.getMessage()));
}
} else {
throw new CloudConnectorException(String.format("Import of %s did not return any task or status object", name));
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackImageVerifier method getStatus.
public ImageStatus getStatus(OSClient<?> osClient, String name) {
ImageStatus imageStatus;
List<? extends Image> images = osClient.imagesV2().list(Collections.singletonMap("name", name));
if (images == null || images.isEmpty()) {
imageStatus = null;
LOGGER.error("OpenStack image: {} not found", name);
List<? extends Image> allImages = osClient.imagesV2().list();
if (allImages != null) {
for (Image image : allImages) {
LOGGER.info("Available images: {}, entry: {}", image.getName(), image);
}
}
LOGGER.warn("OpenStack image: {} not found", name);
} else if (images.size() > 1) {
for (Image image : images) {
LOGGER.info("Multiple images found: {}, entry: {}", image.getName(), image);
}
List<String> imageIds = images.stream().map(Image::getId).collect(Collectors.toList());
throw new CloudConnectorException(String.format("Multiple OpenStack images found with ids: %s, image name: %s", String.join(", ", imageIds), name));
} else {
LOGGER.info("OpenStack Image found: {}, entry: {}", name, images);
imageStatus = images.get(0).getStatus();
}
return imageStatus;
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackClient method createAccessOrToken.
private void createAccessOrToken(AuthenticatedContext authenticatedContext) {
Access access = createAccess(authenticatedContext.getCloudCredential());
Token token = createToken(authenticatedContext.getCloudCredential());
if (token == null && access == null) {
throw new CloudConnectorException("Unsupported keystone version");
} else if (token != null) {
authenticatedContext.putParameter(Token.class, token);
} else {
authenticatedContext.putParameter(Access.class, access);
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackClient method getRegion.
public Set<String> getRegion(CloudCredential cloudCredential) {
Access access = createAccess(cloudCredential);
Token token = createToken(cloudCredential);
Set<String> regions = new HashSet<>();
if (token == null && access == null) {
throw new CloudConnectorException("Unsupported keystone version");
} else if (token != null) {
for (Service service : token.getCatalog()) {
for (Endpoint endpoint : service.getEndpoints()) {
regions.add(endpoint.getRegion());
}
}
} else {
for (Access.Service service : access.getServiceCatalog()) {
for (org.openstack4j.model.identity.v2.Endpoint endpoint : service.getEndpoints()) {
regions.add(endpoint.getRegion());
}
}
}
LOGGER.info("regions from openstack: {}", regions);
return regions;
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException 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));
}
}
Aggregations