Search in sources :

Example 21 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildTestDataDisks.

@Test
public void buildTestDataDisks() {
    // GIVEN
    Network network = new Network(new Subnet("testSubnet"));
    Map<String, String> parameters = new HashMap<>();
    parameters.put("persistentStorage", "persistentStorageTest");
    parameters.put("attachedStorageOption", "attachedStorageOptionTest");
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    groups.add(new Group(name, InstanceGroupType.GATEWAY, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
    // WHEN
    when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
    when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
    when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
    String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
    // THEN
    gson.fromJson(templateString, Map.class);
    assertThat(templateString, containsString("[concat('datadisk', 'm0', '0')]"));
    assertThat(templateString, containsString("[concat('datadisk', 'm0', '1')]"));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) Matchers.containsString(org.hamcrest.Matchers.containsString) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 22 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AzureTemplateBuilderTest method buildWithPublicIpAndFirewall.

@Test
public void buildWithPublicIpAndFirewall() {
    // GIVEN
    Network network = new Network(new Subnet("testSubnet"));
    when(azureUtils.isPrivateIp(any())).then(invocation -> false);
    when(azureUtils.isNoSecurityGroups(any())).then(invocation -> false);
    when(defaultCostTaggingService.prepareAllTagsForTemplate()).thenReturn(defaultTags);
    Map<String, String> parameters = new HashMap<>();
    parameters.put("persistentStorage", "persistentStorageTest");
    parameters.put("attachedStorageOption", "attachedStorageOptionTest");
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    cloudStack = new CloudStack(groups, network, image, parameters, tags, azureTemplateBuilder.getTemplateString(), instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
    azureStackView = new AzureStackView("mystack", 3, groups, azureStorageView, azureSubnetStrategy);
    // WHEN
    when(azureStorage.getImageStorageName(any(AzureCredentialView.class), any(CloudContext.class), any(CloudStack.class))).thenReturn("test");
    when(azureStorage.getDiskContainerName(any(CloudContext.class))).thenReturn("testStorageContainer");
    String templateString = azureTemplateBuilder.build(stackName, CUSTOM_IMAGE_NAME, azureCredentialView, azureStackView, cloudContext, cloudStack);
    // THEN
    gson.fromJson(templateString, Map.class);
    assertThat(templateString, containsString("publicIPAddress"));
    assertThat(templateString, containsString("networkSecurityGroups"));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureStackView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView) Matchers.containsString(org.hamcrest.Matchers.containsString) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 23 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class AzureUtilsTest method shouldAdjustResourceNameLengthIfItsTooLong.

@Test
public void shouldAdjustResourceNameLengthIfItsTooLong() {
    // GIVEN
    CloudContext context = new CloudContext(7899L, "thisisaverylongazureresourcenamewhichneedstobeshortened", "dummy1", "dummy2");
    // WHEN
    String testResult = underTest.getStackName(context);
    // THEN
    Assert.assertNotNull("The generated name must not be null!", testResult);
    assertEquals("The resource name is not the excepted one!", "thisisaverylongazureresourcenamewhichneedstobe7899", testResult);
    Assert.assertTrue("The resource name length is wrong", testResult.length() == Integer.parseInt(MAX_RESOURCE_NAME_LENGTH));
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Test(org.junit.Test)

Example 24 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class GcpProvisionSetup method prepareImage.

@Override
public void prepareImage(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    CloudCredential credential = authenticatedContext.getCloudCredential();
    CloudContext cloudContext = authenticatedContext.getCloudContext();
    try {
        String projectId = getProjectId(credential);
        String imageName = image.getImageName();
        Compute compute = buildCompute(credential);
        ImageList list = compute.images().list(projectId).execute();
        if (!containsSpecificImage(list, imageName)) {
            Storage storage = buildStorage(credential, cloudContext.getName());
            Bucket bucket = new Bucket();
            bucket.setName(String.format("%s-%s-%d", projectId, cloudContext.getName(), cloudContext.getId()));
            bucket.setStorageClass("STANDARD");
            try {
                Buckets.Insert ins = storage.buckets().insert(projectId, bucket);
                ins.execute();
            } catch (GoogleJsonResponseException ex) {
                if (ex.getStatusCode() != HttpStatus.SC_CONFLICT) {
                    throw ex;
                }
            }
            String tarName = getTarName(imageName);
            Copy copy = storage.objects().copy(getBucket(imageName), tarName, bucket.getName(), tarName, new StorageObject());
            copy.execute();
            Image gcpApiImage = new Image();
            gcpApiImage.setName(getImageName(imageName));
            RawDisk rawDisk = new RawDisk();
            rawDisk.setSource(String.format("http://storage.googleapis.com/%s/%s", bucket.getName(), tarName));
            gcpApiImage.setRawDisk(rawDisk);
            Insert ins = compute.images().insert(projectId, gcpApiImage);
            ins.execute();
        }
    } catch (Exception e) {
        Long stackId = cloudContext.getId();
        String msg = String.format("Error occurred on %s stack during the setup: %s", stackId, e.getMessage());
        LOGGER.error(msg, e);
        throw new CloudConnectorException(msg, e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Image(com.google.api.services.compute.model.Image) Insert(com.google.api.services.compute.Compute.Images.Insert) Buckets(com.google.api.services.storage.Storage.Buckets) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) ImageList(com.google.api.services.compute.model.ImageList) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Storage(com.google.api.services.storage.Storage) GcpStackUtil.buildStorage(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildStorage) GcpStackUtil.getBucket(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.getBucket) Bucket(com.google.api.services.storage.model.Bucket) Copy(com.google.api.services.storage.Storage.Objects.Copy) GcpStackUtil.buildCompute(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute) Compute(com.google.api.services.compute.Compute) RawDisk(com.google.api.services.compute.model.Image.RawDisk)

Example 25 with CloudContext

use of com.sequenceiq.cloudbreak.cloud.context.CloudContext in project cloudbreak by hortonworks.

the class GcpInstanceResourceBuilderTest method setUp.

@Before
public void setUp() {
    privateId = 0L;
    name = "master";
    flavor = "m1.medium";
    instanceId = "SOME_ID";
    volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    security = new Security(rules, null);
    Location location = Location.location(Region.region("region"), AvailabilityZone.availabilityZone("az"));
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
    image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
    CloudContext cloudContext = new CloudContext(privateId, "testname", "GCP", "owner");
    CloudCredential cloudCredential = new CloudCredential(privateId, "credentialname");
    cloudCredential.putParameter("projectId", "projectId");
    String projectId = GcpStackUtil.getProjectId(cloudCredential);
    String serviceAccountId = GcpStackUtil.getServiceAccountId(cloudCredential);
    authenticatedContext = new AuthenticatedContext(cloudContext, cloudCredential);
    context = new GcpContext(cloudContext.getName(), location, projectId, serviceAccountId, compute, false, 30, false);
    List<CloudResource> networkResources = Arrays.asList(new Builder().type(ResourceType.GCP_NETWORK).name("network-test").build());
    context.addNetworkResources(networkResources);
    operation = new Operation();
    operation.setName("operation");
    operation.setHttpErrorStatusCode(null);
    GcpResourceNameService resourceNameService = new GcpResourceNameService();
    ReflectionTestUtils.setField(resourceNameService, "maxResourceNameLength", 50);
    ReflectionTestUtils.setField(builder, "resourceNameService", resourceNameService);
}
Also used : PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) GcpResourceNameService(com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Operation(com.google.api.services.compute.model.Operation) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) GcpContext(com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Before(org.junit.Before)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)100 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)43 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)34 Test (org.junit.Test)34 Group (com.sequenceiq.cloudbreak.cloud.model.Group)33 HashMap (java.util.HashMap)33 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)32 Location (com.sequenceiq.cloudbreak.cloud.model.Location)31 Network (com.sequenceiq.cloudbreak.cloud.model.Network)31 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)31 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)25 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)19 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)15 ArrayList (java.util.ArrayList)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14