Search in sources :

Example 41 with CloudConnectorException

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);
    }
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) FreeMarkerTemplateUtils.processTemplateIntoString(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString) IOException(java.io.IOException) NovaInstanceView(com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView) Template(freemarker.template.Template) OpenStackGroupView(com.sequenceiq.cloudbreak.cloud.openstack.view.OpenStackGroupView)

Example 42 with CloudConnectorException

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);
    }
}
Also used : Keypair(org.openstack4j.model.compute.Keypair) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ActionWentFailException(com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)

Example 43 with CloudConnectorException

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;
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GlanceTask(org.openstack4j.openstack.image.v2.domain.GlanceTask) Test(org.junit.Test)

Example 44 with CloudConnectorException

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));
    }
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Flavor(org.openstack4j.model.compute.Flavor) HashSet(java.util.HashSet)

Example 45 with CloudConnectorException

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());
}
Also used : Task(org.openstack4j.model.image.v2.Task) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)

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