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();
}
use of org.apache.heron.spi.common.Config in project heron by twitter.
the class AuroraScheduler method getController.
/**
* Get an AuroraController based on the config and runtime
*
* @return AuroraController
*/
protected AuroraController getController() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Boolean cliController = config.getBooleanValue(Key.AURORA_CONTROLLER_CLASS);
Config localConfig = Config.toLocalMode(this.config);
if (cliController) {
return new AuroraCLIController(Runtime.topologyName(runtime), Context.cluster(localConfig), Context.role(localConfig), Context.environ(localConfig), AuroraContext.getHeronAuroraPath(localConfig), Context.verbose(localConfig));
} else {
return new AuroraHeronShellController(Runtime.topologyName(runtime), Context.cluster(localConfig), Context.role(localConfig), Context.environ(localConfig), AuroraContext.getHeronAuroraPath(localConfig), Context.verbose(localConfig), localConfig);
}
}
use of org.apache.heron.spi.common.Config in project heron by twitter.
the class KubernetesContextTest method testVolumesFromCLIDisabled.
@Test
public void testVolumesFromCLIDisabled() {
Assert.assertFalse(KubernetesContext.getVolumesFromCLIDisabled(config));
Assert.assertFalse(KubernetesContext.getVolumesFromCLIDisabled(configWithPodTemplateConfigMap));
final Config configWithPodTemplateConfigMapOff = Config.newBuilder().put(KubernetesContext.KUBERNETES_POD_TEMPLATE_LOCATION, POD_TEMPLATE_CONFIGMAP_NAME).put(KubernetesContext.KUBERNETES_VOLUME_FROM_CLI_DISABLED, "TRUE").build();
Assert.assertTrue(KubernetesContext.getVolumesFromCLIDisabled(configWithPodTemplateConfigMapOff));
}
use of org.apache.heron.spi.common.Config in project heron by twitter.
the class KubernetesContextTest method testGetVolumeConfigsErrors.
@Test
public void testGetVolumeConfigsErrors() {
final String prefix = KubernetesContext.KUBERNETES_VOLUME_CLAIM_PREFIX;
final String volumeNameValid = "volume-name-valid";
final String volumeNameInvalid = "volume-Name-Invalid";
final String passingValue = "should-pass";
final String failureValue = "Should-Fail";
final String generalFailureMessage = "Invalid Volume configuration";
final String keyPattern = String.format(KubernetesContext.KUBERNETES_VOLUME_CLAIM_PREFIX + "%%s.%%s", KubernetesConstants.EXECUTOR_NAME);
final List<TestTuple<Config, String>> testCases = new LinkedList<>();
// Invalid option key test.
final Config configInvalidOption = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "claimName"), passingValue).put(String.format(keyPattern, volumeNameValid, "storageClassName"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).put(String.format(keyPattern, volumeNameValid, "volumeMode"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "server"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).put(String.format(keyPattern, volumeNameValid, "type"), passingValue).put(String.format(keyPattern, volumeNameValid, "medium"), passingValue).put(String.format(keyPattern, volumeNameValid, "NonExistentKey"), failureValue).build();
testCases.add(new TestTuple<>("Invalid option key should trigger exception", configInvalidOption, generalFailureMessage));
// Invalid Volume Name.
final Config configInvalidVolumeName = Config.newBuilder().put(String.format(keyPattern, volumeNameInvalid, "path"), failureValue).build();
testCases.add(new TestTuple<>("Invalid Volume Name should trigger exception", configInvalidVolumeName, "lowercase RFC-1123"));
// Required Path.
final Config configRequiredPath = Config.newBuilder().put(String.format(keyPattern, volumeNameValid, "claimName"), passingValue).put(String.format(keyPattern, volumeNameValid, "storageClassName"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).put(String.format(keyPattern, volumeNameValid, "volumeMode"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "server"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).put(String.format(keyPattern, volumeNameValid, "type"), passingValue).put(String.format(keyPattern, volumeNameValid, "medium"), passingValue).build();
testCases.add(new TestTuple<>("Missing path should trigger exception", configRequiredPath, "All Volumes require a 'path'."));
// Disabled.
final Config configDisabled = Config.newBuilder().put(KubernetesContext.KUBERNETES_VOLUME_FROM_CLI_DISABLED, "true").put(String.format(keyPattern, volumeNameValid, "claimName"), passingValue).put(String.format(keyPattern, volumeNameValid, "storageClassName"), passingValue).put(String.format(keyPattern, volumeNameValid, "sizeLimit"), passingValue).put(String.format(keyPattern, volumeNameValid, "accessModes"), passingValue).put(String.format(keyPattern, volumeNameValid, "volumeMode"), passingValue).put(String.format(keyPattern, volumeNameValid, "path"), passingValue).put(String.format(keyPattern, volumeNameValid, "subPath"), passingValue).put(String.format(keyPattern, volumeNameValid, "server"), passingValue).put(String.format(keyPattern, volumeNameValid, "readOnly"), passingValue).put(String.format(keyPattern, volumeNameValid, "type"), passingValue).put(String.format(keyPattern, volumeNameValid, "medium"), passingValue).build();
testCases.add(new TestTuple<>("Disabled functionality should trigger exception", configDisabled, "Configuring Volumes from the CLI is disabled."));
// Testing loop.
for (TestTuple<Config, String> testCase : testCases) {
String message = "";
try {
KubernetesContext.getVolumeConfigs(testCase.input, prefix, true);
} catch (TopologySubmissionException e) {
message = e.getMessage();
}
Assert.assertTrue(testCase.description, message.contains(testCase.expected));
}
}
Aggregations