Search in sources :

Example 31 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class OpenStackFlavorVerifierTest method openStackNullFlavor.

@Test(expected = CloudConnectorException.class)
public void openStackNullFlavor() {
    try {
        Group g1 = new Group("name", InstanceGroupType.GATEWAY, new ArrayList<>(), null, null, null, "loginUserName", "publicKey");
        List<Group> instanceGroups = ImmutableList.of(g1);
        when(flavorService.list()).thenReturn(null);
        underTest.flavorsExist(osClient, instanceGroups);
    } catch (Exception e) {
        Assert.assertEquals("No flavor found on OpenStack", e.getMessage());
        throw e;
    }
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Test(org.junit.Test)

Example 32 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class HeatTemplateBuilderTest method buildTestWithExistingNetworkAndExistingSubnetAndAssignFloatingIpWithExistingSecurityGroups.

@Test
public void buildTestWithExistingNetworkAndExistingSubnetAndAssignFloatingIpWithExistingSecurityGroups() throws Exception {
    assumeTrue("Template doesn't support this feature, required version is '2.x' at least", isTemplateMajorVersionGreaterOrEqualThan(2));
    // GIVEN
    boolean existingNetwork = true;
    boolean existingSubnet = true;
    NeutronNetworkView neutronNetworkView = createNeutronNetworkView("floating_pool_id");
    Group group = groups.get(0);
    groups.clear();
    String cloudSecurityId = "sec-group-id";
    Security security = new Security(Collections.emptyList(), cloudSecurityId);
    Group groupWithSecGroup = new Group(group.getName(), InstanceGroupType.CORE, group.getInstances(), security, null, group.getInstanceAuthentication(), group.getInstanceAuthentication().getLoginUserName(), group.getInstanceAuthentication().getPublicKey());
    groups.add(groupWithSecGroup);
    // 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("cb-sec-group_" + 't')));
    assertThat(templateString, not(containsString("type: OS::Neutron::SecurityGroup")));
    assertThat(templateString, containsString(cloudSecurityId));
    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"));
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Matchers.containsString(org.hamcrest.Matchers.containsString) Security(com.sequenceiq.cloudbreak.cloud.model.Security) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) Test(org.junit.Test)

Example 33 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class MockResourceConnector method launch.

@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AdjustmentType adjustmentType, Long threshold) {
    List<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>();
    for (Group group : stack.getGroups()) {
        for (int i = 0; i < group.getInstancesSize(); i++) {
            CloudResource cloudResource = new Builder().type(ResourceType.MOCK_INSTANCE).status(CommonStatus.CREATED).name("cloudinstance" + cloudResourceStatuses.size()).reference("").persistent(true).build();
            cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, CREATED));
        }
    }
    return cloudResourceStatuses;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 34 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class GroupResourceService method buildResources.

public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Iterable<Group> groups, Network network, Security security) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    List<CloudResourceStatus> results = new ArrayList<>();
    for (GroupResourceBuilder builder : resourceBuilders.group(cloudContext.getPlatform())) {
        PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
        if (pollGroup != null && CANCELLED.equals(pollGroup)) {
            break;
        }
        for (Group group : getOrderedCopy(groups)) {
            try {
                CloudResource buildableResource = builder.create(context, auth, group, network);
                createResource(auth, buildableResource);
                CloudResource resource = builder.build(context, auth, group, network, group.getSecurity(), buildableResource);
                updateResource(auth, resource);
                PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
                List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                context.addGroupResources(group.getName(), Collections.singletonList(resource));
                results.addAll(pollerResult);
            } catch (ResourceNotNeededException e) {
                LOGGER.warn("Skipping resource creation: {}", e.getMessage());
            }
        }
    }
    return results;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GroupResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.GroupResourceBuilder) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ResourceNotNeededException(com.sequenceiq.cloudbreak.cloud.template.ResourceNotNeededException)

Example 35 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group 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());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

Group (com.sequenceiq.cloudbreak.cloud.model.Group)62 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)37 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)36 Test (org.junit.Test)36 Network (com.sequenceiq.cloudbreak.cloud.model.Network)35 HashMap (java.util.HashMap)35 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)33 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)33 Matchers.containsString (org.hamcrest.Matchers.containsString)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)17 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)15 Vpc (com.amazonaws.services.ec2.model.Vpc)15 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)15 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14 Location (com.sequenceiq.cloudbreak.cloud.model.Location)14 ArrayList (java.util.ArrayList)14 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)11 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9