use of com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method launch.
@SuppressWarnings("unchecked")
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) {
String stackName = utils.getStackName(authenticatedContext);
NeutronNetworkView neutronNetworkView = new NeutronNetworkView(stack.getNetwork());
boolean existingNetwork = neutronNetworkView.isExistingNetwork();
String existingSubnetCidr = getExistingSubnetCidr(authenticatedContext, stack);
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnetCidr != null);
modelContext.withGroups(stack.getGroups());
modelContext.withInstanceUserData(stack.getImage());
modelContext.withLocation(authenticatedContext.getCloudContext().getLocation());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(stack.getTemplate());
modelContext.withTags(stack.getTags());
String heatTemplate = heatTemplateBuilder.build(modelContext);
Map<String, String> parameters = heatTemplateBuilder.buildParameters(authenticatedContext, stack, existingNetwork, existingSubnetCidr);
OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
List<CloudResourceStatus> resources;
Stack existingStack = client.heat().stacks().getStackByName(stackName);
if (existingStack == null) {
if (stack.getInstanceAuthentication().getPublicKeyId() == null) {
createKeyPair(authenticatedContext, stack, client);
}
Stack heatStack = client.heat().stacks().create(Builders.stack().name(stackName).template(heatTemplate).disableRollback(false).parameters(parameters).timeoutMins(OPERATION_TIMEOUT).build());
List<CloudResource> cloudResources = collectResources(authenticatedContext, notifier, heatStack, stack, neutronNetworkView);
resources = check(authenticatedContext, cloudResources);
} else {
LOGGER.info("Heat stack already exists: {}", existingStack.getName());
CloudResource cloudResource = new Builder().type(ResourceType.HEAT_STACK).name(existingStack.getId()).build();
resources = Collections.singletonList(new CloudResourceStatus(cloudResource, ResourceStatus.CREATED));
}
LOGGER.debug("Launched resources: {}", resources);
return resources;
}
use of com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method buildTestWithExistingSubnetWithoutExistingNetworkAndAssignFloatingIp.
@Test
public void buildTestWithExistingSubnetWithoutExistingNetworkAndAssignFloatingIp() throws Exception {
// GIVEN
boolean existingNetwork = false;
boolean existingSubnet = true;
NeutronNetworkView neutronNetworkView = createNeutronNetworkView(null);
// WHEN
when(openStackUtil.adjustStackNameLength(Mockito.anyString())).thenReturn("t");
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnet);
modelContext.withGroups(groups);
modelContext.withInstanceUserData(image);
modelContext.withLocation(location());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(heatTemplateBuilder.getTemplate());
String templateString = heatTemplateBuilder.build(modelContext);
// THEN
assertThat(templateString, containsString("name: cb-sec-group_" + 't'));
assertThat(templateString, not(containsString("app_net_id")));
assertThat(templateString, containsString("app_network"));
assertThat(templateString, containsString("subnet_id"));
assertThat(templateString, not(containsString("app_subnet")));
assertThat(templateString, containsString("network_id"));
assertThat(templateString, not(containsString("public_net_id")));
}
use of com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method buildTestWithExistingNetworkAndExistingSubnetAndAssignFloatingIp.
@Test
public void buildTestWithExistingNetworkAndExistingSubnetAndAssignFloatingIp() throws Exception {
// GIVEN
boolean existingNetwork = true;
boolean existingSubnet = true;
NeutronNetworkView neutronNetworkView = createNeutronNetworkView("floating_pool_id");
// WHEN
when(openStackUtil.adjustStackNameLength(Mockito.anyString())).thenReturn("t");
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnet);
modelContext.withGroups(groups);
modelContext.withInstanceUserData(image);
modelContext.withLocation(location());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(heatTemplateBuilder.getTemplate());
String templateString = heatTemplateBuilder.build(modelContext);
// THEN
assertThat(templateString, containsString("cb-sec-group_" + 't'));
assertThat(templateString, containsString("app_net_id"));
assertThat(templateString, not(containsString("app_network")));
assertThat(templateString, containsString("subnet_id"));
assertThat(templateString, not(containsString("app_subnet")));
assertThat(templateString, containsString("network_id"));
assertThat(templateString, containsString("public_net_id"));
}
use of com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method buildTestWithExistingNetworkAndExistingSubnetWithoutAssignFloatingIp.
@Test
public void buildTestWithExistingNetworkAndExistingSubnetWithoutAssignFloatingIp() throws Exception {
// GIVEN
boolean existingNetwork = true;
boolean existingSubnet = true;
NeutronNetworkView neutronNetworkView = createNeutronNetworkView(null);
// WHEN
when(openStackUtil.adjustStackNameLength(Mockito.anyString())).thenReturn("t");
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnet);
modelContext.withGroups(groups);
modelContext.withInstanceUserData(image);
modelContext.withLocation(location());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(heatTemplateBuilder.getTemplate());
String templateString = heatTemplateBuilder.build(modelContext);
// THEN
assertThat(templateString, containsString("name: cb-sec-group_" + 't'));
assertThat(templateString, containsString("app_net_id"));
assertThat(templateString, not(containsString("app_network")));
assertThat(templateString, containsString("subnet_id"));
assertThat(templateString, not(containsString("app_subnet")));
assertThat(templateString, containsString("network_id"));
assertThat(templateString, not(containsString("public_net_id")));
}
use of com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method buildTestWithExistingNetworkAndAssignFloatingIpWithoutExistingSubnetShouldThrowAssertionException.
@Test
@Ignore
public void buildTestWithExistingNetworkAndAssignFloatingIpWithoutExistingSubnetShouldThrowAssertionException() throws Exception {
// GIVEN
boolean existingNetwork = true;
boolean existingSubnet = false;
NeutronNetworkView neutronNetworkView = createNeutronNetworkView("floating_pool_id");
// WHEN
when(openStackUtil.adjustStackNameLength(Mockito.anyString())).thenReturn("t");
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnet);
modelContext.withGroups(groups);
modelContext.withInstanceUserData(image);
modelContext.withLocation(location());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(heatTemplateBuilder.getTemplate());
String templateString = heatTemplateBuilder.build(modelContext);
// THEN
assertThat(templateString, not(containsString("name: cb-sec-group_" + 't')));
assertThat(templateString, not(containsString("app_net_id")));
assertThat(templateString, containsString("app_network"));
assertThat(templateString, not(containsString("subnet_id")));
assertThat(templateString, not(containsString("app_subnet")));
assertThat(templateString, not(containsString("network_id")));
assertThat(templateString, not(containsString("public_net_id")));
}
Aggregations