use of com.sequenceiq.cloudbreak.cloud.model.Network 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.model.Network in project cloudbreak by hortonworks.
the class ParameterGenerator method createCloudStack.
public CloudStack createCloudStack() {
List<Group> groups = new ArrayList<>();
String name = "master";
List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
Security security = new Security(rules, null);
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
Subnet subnet = new Subnet("10.0.0.0/24");
Network network = new Network(subnet);
network.putParameter("publicNetId", "028ffc0c-63c5-4ca0-802a-3ac753eaf76c");
return new CloudStack(groups, network, image, new HashMap<>(), new HashMap<>(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildNetwork.
private Network buildNetwork(Stack stack) {
com.sequenceiq.cloudbreak.domain.Network stackNetwork = stack.getNetwork();
Network result = null;
if (stackNetwork != null) {
Subnet subnet = new Subnet(stackNetwork.getSubnetCIDR());
Json attributes = stackNetwork.getAttributes();
Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
result = new Network(subnet, params);
}
return result;
}
use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class GcpNetworkResourceBuilder method build.
@Override
public CloudResource build(GcpContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) throws Exception {
if (!isExistingNetwork(network)) {
Compute compute = context.getCompute();
String projectId = context.getProjectId();
com.google.api.services.compute.model.Network gcpNetwork = new com.google.api.services.compute.model.Network();
gcpNetwork.setName(resource.getName());
gcpNetwork.setAutoCreateSubnetworks(false);
Insert networkInsert = compute.networks().insert(projectId, gcpNetwork);
try {
Operation operation = networkInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
}
context.putParameter(NETWORK_NAME, resource.getName());
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
}
}
context.putParameter(NETWORK_NAME, resource.getName());
return new Builder().cloudResource(resource).persistent(false).build();
}
use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method convert.
public CloudStack convert(Stack stack, Collection<String> deleteRequestedInstances) {
Image image = null;
List<Group> instanceGroups = buildInstanceGroups(stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), deleteRequestedInstances);
try {
image = imageService.getImage(stack.getId());
} catch (CloudbreakImageNotFoundException e) {
LOGGER.info(e.getMessage());
}
Network network = buildNetwork(stack);
StackTemplate stackTemplate = componentConfigProvider.getStackTemplate(stack.getId());
InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stack.getStackAuthentication());
String template = null;
if (stackTemplate != null) {
template = stackTemplate.getTemplate();
}
return new CloudStack(instanceGroups, network, image, stack.getParameters(), getUserDefinedTags(stack), template, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Aggregations