Skip to content
Permalink
Browse files
This closes #1159
  • Loading branch information
ahgittin committed Jan 19, 2016
2 parents ba913f1 + 58226b7 commit 1c7ab436b60fec5c76606bfb419044c1f2811cde
Showing 2 changed files with 50 additions and 2 deletions.
@@ -53,6 +53,7 @@
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.core.test.entity.TestEntityImpl;
import org.apache.brooklyn.entity.group.DynamicCluster;
import org.apache.brooklyn.entity.group.DynamicFabric;
import org.apache.brooklyn.entity.software.base.SameServerEntity;
import org.apache.brooklyn.entity.stock.BasicEntity;
import org.apache.brooklyn.util.collections.MutableMap;
@@ -69,6 +70,7 @@
import org.testng.annotations.Test;
import org.testng.collections.Lists;

import com.google.common.base.Joiner;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -725,6 +727,48 @@ public void testCreateClusterWithMemberSpec() throws Exception {
}
}

@Test
public void testCreateFabricWithLocationsAtTopLevel() throws Exception {
String yaml = Joiner.on("\n").join(
"services:",
"- type: org.apache.brooklyn.entity.group.DynamicFabric",
" memberSpec:",
" $brooklyn:entitySpec:",
" type: org.apache.brooklyn.core.test.entity.TestEntity",
"locations:",
"- byon(hosts=\"1.1.1.1\")",
"- byon(hosts=\"1.1.1.2\")"
);

Entity app = createAndStartApplication(yaml);
waitForApplicationTasks(app);
DynamicFabric fabric = Iterables.getOnlyElement(Entities.descendants(app, DynamicFabric.class));
Iterable<TestEntity> members = Entities.descendants(fabric, TestEntity.class);

assertEquals(Iterables.size(members), 2);
}

@Test
public void testCreateFabricWithLocationsInline() throws Exception {
String yaml = Joiner.on("\n").join(
"services:",
"- type: org.apache.brooklyn.entity.group.DynamicFabric",
" memberSpec:",
" $brooklyn:entitySpec:",
" type: org.apache.brooklyn.core.test.entity.TestEntity",
" locations:",
" - byon(hosts=\"1.1.1.1\")",
" - byon(hosts=\"1.1.1.2\")"
);

Entity app = createAndStartApplication(yaml);
waitForApplicationTasks(app);
DynamicFabric fabric = Iterables.getOnlyElement(Entities.descendants(app, DynamicFabric.class));
Iterable<TestEntity> members = Entities.descendants(fabric, TestEntity.class);

assertEquals(Iterables.size(members), 2);
}

@Test
public void testEntitySpecConfig() throws Exception {
String yaml =
@@ -18,11 +18,13 @@
*/
package org.apache.brooklyn.entity.group;

import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.brooklyn.util.groovy.GroovyJavaMethods.elvis;
import static org.apache.brooklyn.util.groovy.GroovyJavaMethods.truth;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@@ -41,6 +43,7 @@
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
import org.apache.brooklyn.core.entity.trait.Changeable;
import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.location.Locations;
import org.apache.brooklyn.enricher.stock.Enrichers;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -112,9 +115,10 @@ public void start(Collection<? extends Location> locsO) {
if (locsO!=null) {
addLocations(locsO);
}

Collection<Location> locs = Collections.unmodifiableCollection(Locations.getLocationsCheckingAncestors(getLocations(), this));

List<Location> newLocations = MutableList.copyOf(locsO);
if (newLocations.isEmpty()) newLocations.addAll(getLocations());
if (newLocations.isEmpty()) newLocations.addAll(locs);

Preconditions.checkNotNull(newLocations, "locations must be supplied");
Preconditions.checkArgument(newLocations.size() >= 1, "One or more locations must be supplied");

0 comments on commit 1c7ab43

Please sign in to comment.