use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class HeatTemplateBuilder method build.
public String build(ModelContext modelContext) {
try {
List<NovaInstanceView> novaInstances = new OpenStackGroupView(modelContext.stackName, modelContext.groups, modelContext.tags).getFlatNovaView();
Map<String, Object> model = new HashMap<>();
model.put("cb_stack_name", openStackUtil.adjustStackNameLength(modelContext.stackName));
model.put("agents", novaInstances);
model.put("core_user_data", formatUserData(modelContext.instanceUserData.getUserDataByType(InstanceGroupType.CORE)));
model.put("gateway_user_data", formatUserData(modelContext.instanceUserData.getUserDataByType(InstanceGroupType.GATEWAY)));
model.put("groups", modelContext.groups);
model.put("existingNetwork", modelContext.existingNetwork);
model.put("existingSubnet", modelContext.existingSubnet);
model.put("network", modelContext.neutronNetworkView);
model.putAll(defaultCostTaggingService.prepareAllTagsForTemplate());
AvailabilityZone az = modelContext.location.getAvailabilityZone();
if (az != null && az.value() != null) {
model.put("availability_zone", az.value());
}
Template template = new Template(openStackHeatTemplatePath, modelContext.templateString, freemarkerConfiguration);
String generatedTemplate = processTemplateIntoString(template, model);
LOGGER.debug("Generated Heat template: {}", generatedTemplate);
return generatedTemplate;
} catch (IOException | TemplateException e) {
throw new CloudConnectorException("Failed to process the OpenStack HeatTemplateBuilder", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method createKeyPair.
private void createKeyPair(AuthenticatedContext authenticatedContext, CloudStack stack, OSClient<?> client) {
KeystoneCredentialView keystoneCredential = openStackClient.createKeystoneCredential(authenticatedContext);
String keyPairName = keystoneCredential.getKeyPairName();
if (client.compute().keypairs().get(keyPairName) == null) {
try {
Keypair keyPair = client.compute().keypairs().create(keyPairName, stack.getInstanceAuthentication().getPublicKey());
LOGGER.info("Keypair has been created: {}", keyPair);
} catch (Exception e) {
LOGGER.error("Failed to create keypair", e);
throw new CloudConnectorException(e.getMessage(), e);
}
} else {
LOGGER.info("Keypair already exists: {}", keyPairName);
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackImageImageImporterTest method testImportFailure.
@Test(expected = CloudConnectorException.class)
public void testImportFailure() {
try {
GlanceTask task = Mockito.mock(GlanceTask.class);
when(task.getStatus()).thenReturn(Task.TaskStatus.FAILURE);
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 failed with status: FAILURE, message: USEFUL ERRROR MESSAGE", e.getMessage());
throw e;
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackFlavorVerifier method flavorsExist.
public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) {
if (instanceGroups == null) {
throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null");
}
List<? extends Flavor> flavors = osClient.compute().flavors().list();
if (flavors == null || flavors.isEmpty()) {
throw new CloudConnectorException("No flavor found on OpenStack");
}
Set<String> notFoundFlavors = new HashSet<>();
for (Group instanceGroup : instanceGroups) {
String instanceType = instanceGroup.getReferenceInstanceConfiguration().getTemplate().getFlavor();
boolean found = false;
for (Flavor flavor : flavors) {
if (flavor.getName().equalsIgnoreCase(instanceType)) {
found = true;
break;
}
}
if (!found) {
notFoundFlavors.add(instanceType);
}
}
if (!notFoundFlavors.isEmpty()) {
LOGGER.warn("Not found flavors: {}", notFoundFlavors);
throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors));
}
}
use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.
the class OpenStackImageImporter method importImage.
public void importImage(OSClient osClient, String name) {
String importLocation = openStackImageImportTaskParameters.getImportLocation(name);
LOGGER.info("Import OpenStack image from: {}", importLocation);
if (!urlAccessValidationService.isAccessible(importLocation)) {
throw new CloudConnectorException(String.format("OpenStack image '%s' is not accessible, therefore it cannot be imported automatically", importLocation));
}
Map<String, Object> input = openStackImageImportTaskParameters.buildInput(name);
LOGGER.info("Executing of the following import Task: {}", input);
Task task = osClient.imagesV2().tasks().create(Builders.taskBuilder().type("import").input(input).build());
evaluateTaskStatus(task, name);
LOGGER.info("Task of importing {} image, returned with {}", name, task.getStatus());
}
Aggregations