Search in sources :

Example 1 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerMain method manageTopology.

/**
 * Manager a topology
 * 1. Instantiate necessary resources
 * 2. Valid whether the runtime management is legal
 * 3. Complete the runtime management for a specific command
 */
public void manageTopology() throws TopologyRuntimeManagementException, TManagerException, PackingException {
    String topologyName = Context.topologyName(config);
    // 1. Do prepare work
    // create an instance of state manager
    String statemgrClass = Context.stateManagerClass(config);
    IStateManager statemgr;
    try {
        statemgr = ReflectionUtils.newInstance(statemgrClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new TopologyRuntimeManagementException(String.format("Failed to instantiate state manager class '%s'", statemgrClass), e);
    }
    // Put it in a try block so that we can always clean resources
    try {
        // initialize the statemgr
        statemgr.initialize(config);
        // TODO(mfu): timeout should read from config
        SchedulerStateManagerAdaptor adaptor = new SchedulerStateManagerAdaptor(statemgr, 5000);
        boolean hasExecutionData = validateRuntimeManage(adaptor, topologyName);
        // 2. Try to manage topology if valid
        // invoke the appropriate command to manage the topology
        LOG.log(Level.FINE, "Topology: {0} to be {1}ed", new Object[] { topologyName, command });
        // build the runtime config
        Config runtime = Config.newBuilder().put(Key.TOPOLOGY_NAME, Context.topologyName(config)).put(Key.SCHEDULER_STATE_MANAGER_ADAPTOR, adaptor).build();
        // Create a ISchedulerClient basing on the config
        ISchedulerClient schedulerClient = getSchedulerClient(runtime);
        callRuntimeManagerRunner(runtime, schedulerClient, !hasExecutionData);
    } finally {
        // 3. Do post work basing on the result
        // Currently nothing to do here
        // 4. Close the resources
        SysUtils.closeIgnoringExceptions(statemgr);
    }
}
Also used : IStateManager(org.apache.heron.spi.statemgr.IStateManager) Config(org.apache.heron.spi.common.Config) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Example 2 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyDryRun.

@PrepareForTest({ ReflectionUtils.class, Runtime.class })
@Test(expected = UpdateDryRunResponse.class)
public void testManageTopologyDryRun() throws Exception {
    config = mock(Config.class);
    // prepare packing class
    ResourceCompliantRRPacking repacking = new ResourceCompliantRRPacking();
    when(config.getStringValue(Key.REPACKING_CLASS)).thenReturn(IRepacking.class.getName());
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    when(config.getStringValue(RuntimeManagerRunner.RUNTIME_MANAGER_COMPONENT_PARALLELISM_KEY)).thenReturn("testSpout:4,testBolt:5");
    // mock dry-run mode
    when(config.getBooleanValue(Key.DRY_RUN)).thenReturn(true);
    when(config.getDoubleValue(Key.INSTANCE_CPU)).thenReturn(1.0);
    when(config.getByteAmountValue(Key.INSTANCE_RAM)).thenReturn(ByteAmount.fromGigabytes(1));
    when(config.getByteAmountValue(Key.INSTANCE_DISK)).thenReturn(ByteAmount.fromGigabytes(1));
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, Command.UPDATE));
    // Mock validate runtime
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", eq(IStateManager.class.getName()));
    PowerMockito.doReturn(repacking).when(ReflectionUtils.class, "newInstance", eq(IRepacking.class.getName()));
    doReturn(true).when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Successfully get ISchedulerClient
    ISchedulerClient client = mock(ISchedulerClient.class);
    doReturn(client).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    // Mock updateTopologyHandler of runner
    PowerMockito.mockStatic(Runtime.class);
    SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
    PowerMockito.when(Runtime.schedulerStateManagerAdaptor(any(Config.class))).thenReturn(manager);
    ResourceCompliantRRPacking packing = new ResourceCompliantRRPacking();
    PackingPlans.PackingPlan currentPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
    // the actual topology does not matter
    doReturn(TopologyAPI.Topology.getDefaultInstance()).when(manager).getTopology(eq(TOPOLOGY_NAME));
    doReturn(currentPlan).when(manager).getPackingPlan(eq(TOPOLOGY_NAME));
    try {
        runtimeManagerMain.manageTopology();
    } finally {
        // verify scheduler client is never used
        verifyZeroInteractions(client);
    }
}
Also used : ResourceCompliantRRPacking(org.apache.heron.packing.roundrobin.ResourceCompliantRRPacking) IStateManager(org.apache.heron.spi.statemgr.IStateManager) PackingPlans(org.apache.heron.proto.system.PackingPlans) IRepacking(org.apache.heron.spi.packing.IRepacking) Config(org.apache.heron.spi.common.Config) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyOk.

@PrepareForTest(ReflectionUtils.class)
@Test
public void testManageTopologyOk() throws Exception {
    config = mock(Config.class);
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, MOCK_COMMAND));
    // Valid state manager class
    Mockito.when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(Mockito.mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IStateManager.class.getName()));
    // Legal request
    doReturn(true).when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Successfully get ISchedulerClient
    ISchedulerClient client = mock(ISchedulerClient.class);
    doReturn(client).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    // Happy path
    doNothing().when(runtimeManagerMain).callRuntimeManagerRunner(any(Config.class), eq(client), eq(false));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(org.apache.heron.spi.statemgr.IStateManager) Config(org.apache.heron.spi.common.Config) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerRunnerTest method testRestartTopologyHandlerFailRestartTopology.

@Test(expected = TopologyRuntimeManagementException.class)
public void testRestartTopologyHandlerFailRestartTopology() {
    ISchedulerClient client = mock(ISchedulerClient.class);
    SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.RESTART, client);
    // Restart container 1, not containing TManager
    Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).setContainerIndex(1).build();
    when(config.getIntegerValue(Key.TOPOLOGY_CONTAINER_ID)).thenReturn(1);
    when(client.restartTopology(restartTopologyRequest)).thenReturn(false);
    try {
        runner.restartTopologyHandler(TOPOLOGY_NAME);
    } finally {
        verify(adaptor, never()).deleteTManagerLocation(TOPOLOGY_NAME);
    }
}
Also used : ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) Scheduler(org.apache.heron.proto.scheduler.Scheduler) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerRunnerTest method testUpdateTopologyUserRuntimeConfig.

@PrepareForTest({ NetworkUtils.class, Runtime.class })
@Test
public void testUpdateTopologyUserRuntimeConfig() throws Exception {
    String testConfig = "topology.user:test,testSpout:topology.user:1,testBolt:topology.user:4";
    URL expectedURL = new URL("http://host:1/runtime_config/update?topologyid=topology-id&" + "runtime-config=topology.user:test&runtime-config=testSpout:topology.user:1&" + "runtime-config=testBolt:topology.user:4");
    // Success case
    ISchedulerClient client = mock(ISchedulerClient.class);
    SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
    HttpURLConnection connection = mock(HttpURLConnection.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.UPDATE, client);
    TopologyManager.TManagerLocation location = TopologyManager.TManagerLocation.newBuilder().setTopologyName("topology-name").setTopologyId("topology-id").setHost("host").setControllerPort(1).setServerPort(2).build();
    when(manager.getTManagerLocation(TOPOLOGY_NAME)).thenReturn(location);
    when(connection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
    PowerMockito.mockStatic(Runtime.class);
    PowerMockito.when(Runtime.schedulerStateManagerAdaptor(runtime)).thenReturn(manager);
    PowerMockito.mockStatic(NetworkUtils.class);
    PowerMockito.when(NetworkUtils.getProxiedHttpConnectionIfNeeded(eq(expectedURL), any(NetworkUtils.TunnelConfig.class))).thenReturn(connection);
    runner.updateTopologyUserRuntimeConfig(TOPOLOGY_NAME, testConfig);
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HttpURLConnection(java.net.HttpURLConnection) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) URL(java.net.URL) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ISchedulerClient (org.apache.heron.scheduler.client.ISchedulerClient)14 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)12 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 Scheduler (org.apache.heron.proto.scheduler.Scheduler)7 Config (org.apache.heron.spi.common.Config)5 IStateManager (org.apache.heron.spi.statemgr.IStateManager)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)2 PackingPlans (org.apache.heron.proto.system.PackingPlans)2 PackingPlan (org.apache.heron.spi.packing.PackingPlan)2 Action (com.microsoft.dhalion.core.Action)1 Diagnosis (com.microsoft.dhalion.core.Diagnosis)1 Measurement (com.microsoft.dhalion.core.Measurement)1 ExecutionContext (com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 PackingPlanProvider (org.apache.heron.healthmgr.common.PackingPlanProvider)1 ResourceCompliantRRPacking (org.apache.heron.packing.roundrobin.ResourceCompliantRRPacking)1