use of org.apache.heron.spi.common.Config in project heron by twitter.
the class CommonPackingTests method setUp.
@Before
public void setUp() {
this.spoutParallelism = 4;
this.boltParallelism = 3;
this.totalInstances = this.spoutParallelism + this.boltParallelism;
// Set up the topology and its config. Tests can safely modify the config by reference after the
// topology is created, but those changes will not be reflected in the underlying protobuf
// object Config and Topology objects. This is typically fine for packing tests since they don't
// access the protobuf values.
this.topologyConfig = new org.apache.heron.api.Config();
this.topologyConfig.setTopologyContainerMaxNumInstances(4);
this.topology = getTopology(spoutParallelism, boltParallelism, topologyConfig);
Config config = PackingTestUtils.newTestConfig(this.topology);
this.instanceDefaultResources = new Resource(Context.instanceCpu(config), Context.instanceRam(config), Context.instanceDisk(config));
}
use of org.apache.heron.spi.common.Config in project heron by twitter.
the class V1Controller method mountSecretsAsVolumes.
/**
* Adds <code>Volume Mounts</code> for <code>Secrets</code> to a pod.
* @param podSpec <code>Pod Spec</code> to add secrets to.
*/
private void mountSecretsAsVolumes(V1PodSpec podSpec) {
final Config config = getConfiguration();
final Map<String, String> secrets = KubernetesContext.getPodSecretsToMount(config);
for (Map.Entry<String, String> secret : secrets.entrySet()) {
final V1VolumeMount mount = new V1VolumeMount().name(secret.getKey()).mountPath(secret.getValue());
final V1Volume secretVolume = new V1Volume().name(secret.getKey()).secret(new V1SecretVolumeSourceBuilder().withSecretName(secret.getKey()).build());
podSpec.addVolumesItem(secretVolume);
for (V1Container container : podSpec.getContainers()) {
container.addVolumeMountsItem(mount);
}
}
}
use of org.apache.heron.spi.common.Config in project heron by twitter.
the class V1Controller method addVolumesIfPresent.
/**
* Adds volume to the <code>Pod Spec</code> that Heron requires. Heron's values taking precedence.
* @param spec <code>Pod Spec</code> to be configured.
*/
@VisibleForTesting
protected void addVolumesIfPresent(final V1PodSpec spec) {
final Config config = getConfiguration();
if (KubernetesContext.hasVolume(config)) {
final V1Volume volumeFromConfig = Volumes.get().create(config);
if (volumeFromConfig != null) {
// Merge volumes. Deduplicate using volume's name with Heron defaults taking precedence.
KubernetesUtils.V1ControllerUtils<V1Volume> utils = new KubernetesUtils.V1ControllerUtils<>();
spec.setVolumes(utils.mergeListsDedupe(Collections.singletonList(volumeFromConfig), spec.getVolumes(), Comparator.comparing(V1Volume::getName), "Pod Template Volumes"));
LOG.fine("Adding volume: " + volumeFromConfig);
}
}
}
use of org.apache.heron.spi.common.Config in project heron by twitter.
the class LauncherUtilsTest method constructsRuntimeWithPackingProperly.
@Test
public void constructsRuntimeWithPackingProperly() {
Config runtime = Config.newBuilder().put("key-23", "value-34").build();
Assert.assertNull(Runtime.componentRamMap(runtime));
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
PackingPlan mockPacking = Mockito.mock(PackingPlan.class);
Mockito.when(mockPacking.getComponentRamDistribution()).thenReturn("ramMap");
Mockito.when(mockPacking.getContainers()).thenReturn(containers);
Config newRuntime = LauncherUtils.getInstance().createConfigWithPackingDetails(runtime, mockPacking);
Assert.assertNull(Runtime.componentRamMap(runtime));
Assert.assertEquals("ramMap", Runtime.componentRamMap(newRuntime));
Assert.assertEquals(3, Runtime.numContainers(newRuntime).longValue());
Assert.assertEquals("value-34", newRuntime.getStringValue("key-23"));
}
use of org.apache.heron.spi.common.Config in project heron by twitter.
the class LauncherUtilsTest method generatesPackingPlan.
@Test
public void generatesPackingPlan() throws Exception {
final String PACKING_CLASS = "nonExistingTestPackingClass";
final PackingPlan mockPackingPlan = Mockito.mock(PackingPlan.class);
IPacking mockPacking = Mockito.mock(IPacking.class);
Mockito.when(mockPacking.pack()).thenReturn(mockPackingPlan);
PowerMockito.spy(ReflectionUtils.class);
PowerMockito.doReturn(mockPacking).when(ReflectionUtils.class, "newInstance", PACKING_CLASS);
TopologyAPI.Topology mockTopology = PowerMockito.mock(TopologyAPI.Topology.class);
Config mockConfig = Mockito.mock(Config.class);
Mockito.when(mockConfig.getStringValue(Key.PACKING_CLASS)).thenReturn(PACKING_CLASS);
Mockito.when(mockConfig.get(Key.TOPOLOGY_DEFINITION)).thenReturn(mockTopology);
PackingPlan resultPacking = LauncherUtils.getInstance().createPackingPlan(mockConfig, mockConfig);
Assert.assertEquals(mockPackingPlan, resultPacking);
Mockito.verify(mockPacking).initialize(Mockito.any(Config.class), Mockito.eq(mockTopology));
Mockito.verify(mockPacking).pack();
Mockito.verify(mockPacking).close();
}
Aggregations