use of com.microsoft.dhalion.api.IHealthPolicy in project incubator-heron by apache.
the class HealthManagerTest method testInitialize.
@Test
public void testInitialize() throws Exception {
String topologyName = "testTopology";
Config config = Config.newBuilder().put(Key.SCHEDULER_IS_SERVICE, true).put(Key.TOPOLOGY_NAME, topologyName).put(Key.ENVIRON, "environ").put(Key.CLUSTER, "cluster").build();
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
SchedulerLocation schedulerLocation = SchedulerLocation.newBuilder().setTopologyName(topologyName).setHttpEndpoint("http://127.0.0.1").build();
when(adaptor.getSchedulerLocation(anyString())).thenReturn(schedulerLocation);
AbstractModule baseModule = HealthManager.buildMetricsProviderModule("127.0.0.1", TrackerMetricsProvider.class.getName());
HealthManager healthManager = new HealthManager(config, baseModule);
Map<String, Object> policy = new HashMap<>();
policy.put(PolicyConfigKey.HEALTH_POLICY_CLASS.key(), TestPolicy.class.getName());
policy.put("test-config", "test-value");
String[] policyIds = { "policy" };
HealthPolicyConfigReader policyConfigProvider = mock(HealthPolicyConfigReader.class);
when(policyConfigProvider.getPolicyIds()).thenReturn(Arrays.asList(policyIds));
when(policyConfigProvider.getPolicyConfig("policy")).thenReturn(policy);
HealthManager spyHealthMgr = spy(healthManager);
doReturn(adaptor).when(spyHealthMgr).createStateMgrAdaptor();
doReturn(policyConfigProvider).when(spyHealthMgr).createPolicyConfigReader();
spyHealthMgr.initialize();
List<IHealthPolicy> healthPolicies = spyHealthMgr.getHealthPolicies();
assertEquals(1, healthPolicies.size());
TestPolicy healthPolicy = (TestPolicy) healthPolicies.iterator().next();
assertNotNull(healthPolicy.schedulerClient);
assertEquals(healthPolicy.stateMgrAdaptor, adaptor);
assertNotNull(healthPolicy.metricsProvider);
assertEquals(healthPolicy.config.getConfig("test-config"), "test-value");
}
use of com.microsoft.dhalion.api.IHealthPolicy in project incubator-heron by apache.
the class HealthManager method initializePolicies.
// we don't know what T is until runtime
@SuppressWarnings("unchecked")
private void initializePolicies() throws ClassNotFoundException {
List<String> policyIds = policyConfigReader.getPolicyIds();
for (String policyId : policyIds) {
Map<String, Object> policyConfigMap = policyConfigReader.getPolicyConfig(policyId);
HealthPolicyConfig policyConfig = new HealthPolicyConfig(policyConfigMap);
String policyClassName = policyConfig.getPolicyClass();
LOG.info(String.format("Initializing %s with class %s", policyId, policyClassName));
Class<IHealthPolicy> policyClass = (Class<IHealthPolicy>) this.getClass().getClassLoader().loadClass(policyClassName);
AbstractModule module = constructPolicySpecificModule(policyConfig);
IHealthPolicy policy = injector.createChildInjector(module).getInstance(policyClass);
healthPolicies.add(policy);
}
}
use of com.microsoft.dhalion.api.IHealthPolicy in project heron by twitter.
the class HealthManagerTest method testInitialize.
@Test
public void testInitialize() throws Exception {
String topologyName = "testTopology";
Config config = Config.newBuilder().put(Key.SCHEDULER_IS_SERVICE, true).put(Key.TOPOLOGY_NAME, topologyName).put(Key.ENVIRON, "environ").put(Key.CLUSTER, "cluster").build();
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
SchedulerLocation schedulerLocation = SchedulerLocation.newBuilder().setTopologyName(topologyName).setHttpEndpoint("http://127.0.0.1").build();
when(adaptor.getSchedulerLocation(anyString())).thenReturn(schedulerLocation);
HealthManagerMetrics publishingMetrics = mock(HealthManagerMetrics.class);
AbstractModule baseModule = HealthManager.buildBaseModule("127.0.0.1", TrackerMetricsProvider.class.getName(), publishingMetrics);
HealthManager healthManager = new HealthManager(config, baseModule);
Map<String, Object> policy = new HashMap<>();
policy.put(PolicyConfigKey.HEALTH_POLICY_CLASS.key(), TestPolicy.class.getName());
policy.put("test-config", "test-value");
String[] policyIds = { "policy" };
HealthPolicyConfigReader policyConfigProvider = mock(HealthPolicyConfigReader.class);
when(policyConfigProvider.getPolicyIds()).thenReturn(Arrays.asList(policyIds));
when(policyConfigProvider.getPolicyConfig("policy")).thenReturn(policy);
HealthManager spyHealthMgr = spy(healthManager);
doReturn(adaptor).when(spyHealthMgr).createStateMgrAdaptor();
doReturn(policyConfigProvider).when(spyHealthMgr).createPolicyConfigReader();
spyHealthMgr.initialize();
List<IHealthPolicy> healthPolicies = spyHealthMgr.getHealthPolicies();
assertEquals(1, healthPolicies.size());
TestPolicy healthPolicy = (TestPolicy) healthPolicies.iterator().next();
assertNotNull(healthPolicy.schedulerClient);
assertEquals(healthPolicy.stateMgrAdaptor, adaptor);
assertNotNull(healthPolicy.metricsProvider);
assertEquals(healthPolicy.config.getConfig("test-config"), "test-value");
}
use of com.microsoft.dhalion.api.IHealthPolicy in project heron by twitter.
the class HealthManager method initializePolicies.
// we don't know what T is until runtime
@SuppressWarnings("unchecked")
private void initializePolicies() throws ClassNotFoundException {
List<String> policyIds = policyConfigReader.getPolicyIds();
for (String policyId : policyIds) {
Map<String, Object> policyConfigMap = policyConfigReader.getPolicyConfig(policyId);
HealthPolicyConfig policyConfig = new HealthPolicyConfig(policyConfigMap);
String policyClassName = policyConfig.getPolicyClass();
LOG.info(String.format("Initializing %s with class %s", policyId, policyClassName));
Class<IHealthPolicy> policyClass = (Class<IHealthPolicy>) this.getClass().getClassLoader().loadClass(policyClassName);
AbstractModule module = constructPolicySpecificModule(policyId, policyConfig);
IHealthPolicy policy = injector.createChildInjector(module).getInstance(policyClass);
healthPolicies.add(policy);
}
}
Aggregations