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