Search in sources :

Example 11 with Service

use of org.apache.hadoop.service.Service in project hadoop by apache.

the class TestAuxServices method testAuxUnexpectedStop.

@Test
public void testAuxUnexpectedStop() {
    Configuration conf = new Configuration();
    conf.setStrings(YarnConfiguration.NM_AUX_SERVICES, new String[] { "Asrv", "Bsrv" });
    conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Asrv"), ServiceA.class, Service.class);
    conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Bsrv"), ServiceB.class, Service.class);
    final AuxServices aux = new AuxServices();
    aux.init(conf);
    aux.start();
    Service s = aux.getServices().iterator().next();
    s.stop();
    assertEquals("Auxiliary service stopped, but AuxService unaffected.", STOPPED, aux.getServiceState());
    assertTrue(aux.getServices().isEmpty());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) AuxiliaryService(org.apache.hadoop.yarn.server.api.AuxiliaryService) Service(org.apache.hadoop.service.Service) Test(org.junit.Test)

Example 12 with Service

use of org.apache.hadoop.service.Service in project hadoop by apache.

the class TestServiceLifecycle method testStartInInitService.

@Test
public void testStartInInitService() throws Throwable {
    Service service = new StartInInitService();
    BreakableStateChangeListener listener = new BreakableStateChangeListener();
    service.registerServiceListener(listener);
    service.init(new Configuration());
    assertServiceInState(service, Service.STATE.STARTED);
    assertEventCount(listener, 1);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) AbstractService(org.apache.hadoop.service.AbstractService) Service(org.apache.hadoop.service.Service) Test(org.junit.Test)

Example 13 with Service

use of org.apache.hadoop.service.Service in project hadoop by apache.

the class TestProportionalCapacityPreemptionPolicy method testPolicyInitializeAfterSchedulerInitialized.

@Test
public void testPolicyInitializeAfterSchedulerInitialized() {
    @SuppressWarnings("resource") MockRM rm = new MockRM(conf);
    rm.init(conf);
    // after scheduler got initialized
    for (Service service : rm.getRMActiveService().getServices()) {
        if (service instanceof SchedulingMonitor) {
            ProportionalCapacityPreemptionPolicy policy = (ProportionalCapacityPreemptionPolicy) ((SchedulingMonitor) service).getSchedulingEditPolicy();
            assertNotNull(policy.getResourceCalculator());
            return;
        }
    }
    fail("Failed to find SchedulingMonitor service, please check what happened");
}
Also used : SchedulingMonitor(org.apache.hadoop.yarn.server.resourcemanager.monitor.SchedulingMonitor) Service(org.apache.hadoop.service.Service) MockRM(org.apache.hadoop.yarn.server.resourcemanager.MockRM) Test(org.junit.Test)

Example 14 with Service

use of org.apache.hadoop.service.Service in project hadoop by apache.

the class TestAuxServices method testAuxServicesMeta.

@Test
public void testAuxServicesMeta() {
    Configuration conf = new Configuration();
    conf.setStrings(YarnConfiguration.NM_AUX_SERVICES, new String[] { "Asrv", "Bsrv" });
    conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Asrv"), ServiceA.class, Service.class);
    conf.setClass(String.format(YarnConfiguration.NM_AUX_SERVICE_FMT, "Bsrv"), ServiceB.class, Service.class);
    final AuxServices aux = new AuxServices();
    aux.init(conf);
    int latch = 1;
    for (Service s : aux.getServices()) {
        assertEquals(INITED, s.getServiceState());
        if (s instanceof ServiceA) {
            latch *= 2;
        } else if (s instanceof ServiceB) {
            latch *= 3;
        } else
            fail("Unexpected service type " + s.getClass());
    }
    assertEquals("Invalid mix of services", 6, latch);
    aux.start();
    for (Service s : aux.getServices()) {
        assertEquals(STARTED, s.getServiceState());
    }
    Map<String, ByteBuffer> meta = aux.getMetaData();
    assertEquals(2, meta.size());
    assertEquals("A", new String(meta.get("Asrv").array()));
    assertEquals("B", new String(meta.get("Bsrv").array()));
    aux.stop();
    for (Service s : aux.getServices()) {
        assertEquals(STOPPED, s.getServiceState());
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) AuxiliaryService(org.apache.hadoop.yarn.server.api.AuxiliaryService) Service(org.apache.hadoop.service.Service) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 15 with Service

use of org.apache.hadoop.service.Service in project hadoop by apache.

the class TestServiceLifecycle method testStopInInitService.

@Test
public void testStopInInitService() throws Throwable {
    Service service = new StopInInitService();
    BreakableStateChangeListener listener = new BreakableStateChangeListener();
    service.registerServiceListener(listener);
    service.init(new Configuration());
    assertServiceInState(service, Service.STATE.STOPPED);
    assertEventCount(listener, 1);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) AbstractService(org.apache.hadoop.service.AbstractService) Service(org.apache.hadoop.service.Service) Test(org.junit.Test)

Aggregations

Service (org.apache.hadoop.service.Service)17 Configuration (org.apache.hadoop.conf.Configuration)9 Test (org.junit.Test)9 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)6 AbstractService (org.apache.hadoop.service.AbstractService)5 IOException (java.io.IOException)4 AuxiliaryService (org.apache.hadoop.yarn.server.api.AuxiliaryService)4 ResourceManager (org.apache.hadoop.yarn.server.resourcemanager.ResourceManager)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 MRApp (org.apache.hadoop.mapreduce.v2.app.MRApp)2 ServiceStateChangeListener (org.apache.hadoop.service.ServiceStateChangeListener)2 SchedulingMonitor (org.apache.hadoop.yarn.server.resourcemanager.monitor.SchedulingMonitor)2 BeforeClass (org.junit.BeforeClass)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ByteBuffer (java.nio.ByteBuffer)1 MRClientProtocol (org.apache.hadoop.mapreduce.v2.api.MRClientProtocol)1 GetDiagnosticsRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDiagnosticsRequest)1 GetDiagnosticsResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDiagnosticsResponse)1 GetTaskAttemptCompletionEventsRequest (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptCompletionEventsRequest)1 GetTaskAttemptCompletionEventsResponse (org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptCompletionEventsResponse)1