Search in sources :

Example 11 with ApplicationTimeoutType

use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.

the class RMWebServices method getAppTimeout.

@GET
@Path("/apps/{appid}/timeouts/{type}")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppTimeoutInfo getAppTimeout(@Context HttpServletRequest hsr, @PathParam("appid") String appId, @PathParam("type") String type) throws AuthorizationException {
    init();
    RMApp app = validateAppTimeoutRequest(hsr, appId);
    ApplicationTimeoutType appTimeoutType = parseTimeoutType(type);
    Long timeoutValue = app.getApplicationTimeouts().get(appTimeoutType);
    AppTimeoutInfo timeout = constructAppTimeoutDao(appTimeoutType, timeoutValue);
    return timeout;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with ApplicationTimeoutType

use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.

the class TestApplicationLifetimeMonitor method testUpdateApplicationTimeoutForStateStoreUpdateFail.

@Test(timeout = 60000)
public void testUpdateApplicationTimeoutForStateStoreUpdateFail() throws Exception {
    MockRM rm1 = null;
    try {
        conf.set(YarnConfiguration.RM_STORE, MemoryRMStateStore.class.getName());
        MemoryRMStateStore memStore = new MemoryRMStateStore() {

            private int count = 0;

            @Override
            public synchronized void updateApplicationStateInternal(ApplicationId appId, ApplicationStateData appState) throws Exception {
                // fail only 1 time.
                if (count++ == 0) {
                    throw new Exception("State-store update failed");
                }
                super.updateApplicationStateInternal(appId, appState);
            }
        };
        memStore.init(conf);
        rm1 = new MockRM(conf, memStore);
        rm1.start();
        MockNM nm1 = new MockNM("127.0.0.1:1234", 8192, rm1.getResourceTrackerService());
        nm1.registerNode();
        nm1.nodeHeartbeat(true);
        long appLifetime = 30L;
        Map<ApplicationTimeoutType, Long> timeouts = new HashMap<ApplicationTimeoutType, Long>();
        timeouts.put(ApplicationTimeoutType.LIFETIME, appLifetime);
        RMApp app1 = rm1.submitApp(200, Priority.newInstance(0), timeouts);
        Map<ApplicationTimeoutType, String> updateTimeout = new HashMap<ApplicationTimeoutType, String>();
        long newLifetime = 10L;
        // update 10L seconds more to timeout i.e 30L seconds overall
        updateTimeout.put(ApplicationTimeoutType.LIFETIME, Times.formatISO8601(System.currentTimeMillis() + newLifetime * 1000));
        UpdateApplicationTimeoutsRequest request = UpdateApplicationTimeoutsRequest.newInstance(app1.getApplicationId(), updateTimeout);
        Map<ApplicationTimeoutType, Long> applicationTimeouts = app1.getApplicationTimeouts();
        // has old timeout time
        long beforeUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);
        try {
            // update app2 lifetime to new time i.e now + timeout
            rm1.getRMContext().getClientRMService().updateApplicationTimeouts(request);
            fail("Update application should fail.");
        } catch (YarnException e) {
            // expected
            assertTrue("State-store exception does not containe appId", e.getMessage().contains(app1.getApplicationId().toString()));
        }
        applicationTimeouts = app1.getApplicationTimeouts();
        // has old timeout time
        long afterUpdate = applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);
        Assert.assertEquals("Application timeout is updated", beforeUpdate, afterUpdate);
        rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED);
        // verify for app killed with updated lifetime
        Assert.assertTrue("Application killed before lifetime value", app1.getFinishTime() > afterUpdate);
    } finally {
        stopRM(rm1);
    }
}
Also used : HashMap(java.util.HashMap) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) MockRM(org.apache.hadoop.yarn.server.resourcemanager.MockRM) ApplicationStateData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UpdateApplicationTimeoutsRequest(org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsRequest) MemoryRMStateStore(org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 13 with ApplicationTimeoutType

use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.

the class ClientRMService method updateApplicationTimeouts.

@Override
public UpdateApplicationTimeoutsResponse updateApplicationTimeouts(UpdateApplicationTimeoutsRequest request) throws YarnException, IOException {
    ApplicationId applicationId = request.getApplicationId();
    Map<ApplicationTimeoutType, String> applicationTimeouts = request.getApplicationTimeouts();
    UserGroupInformation callerUGI = getCallerUgi(applicationId, AuditConstants.UPDATE_APP_TIMEOUTS);
    RMApp application = verifyUserAccessForRMApp(applicationId, callerUGI, AuditConstants.UPDATE_APP_TIMEOUTS);
    if (applicationTimeouts.isEmpty()) {
        String message = "At least one ApplicationTimeoutType should be configured" + " for updating timeouts.";
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_TIMEOUTS, "UNKNOWN", "ClientRMService", message, applicationId);
        throw RPCUtil.getRemoteException(message);
    }
    UpdateApplicationTimeoutsResponse response = recordFactory.newRecordInstance(UpdateApplicationTimeoutsResponse.class);
    RMAppState state = application.getState();
    if (!EnumSet.of(RMAppState.SUBMITTED, RMAppState.ACCEPTED, RMAppState.RUNNING).contains(state)) {
        if (COMPLETED_APP_STATES.contains(state)) {
            // If Application is in any of the final states, update timeout
            // can be skipped rather throwing exception.
            RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_TIMEOUTS, "ClientRMService", applicationId);
            return response;
        }
        String msg = "Application is in " + state + " state can not update timeout.";
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_TIMEOUTS, "UNKNOWN", "ClientRMService", msg);
        throw RPCUtil.getRemoteException(msg);
    }
    try {
        rmAppManager.updateApplicationTimeout(application, applicationTimeouts);
    } catch (YarnException ex) {
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_TIMEOUTS, "UNKNOWN", "ClientRMService", ex.getMessage());
        throw ex;
    }
    RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_TIMEOUTS, "ClientRMService", applicationId);
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppState(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppState) ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) UpdateApplicationTimeoutsResponse(org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsResponse) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 14 with ApplicationTimeoutType

use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.

the class ApplicationStateDataPBImpl method initApplicationTimeout.

private void initApplicationTimeout() {
    if (this.applicationTimeouts != null) {
        return;
    }
    ApplicationStateDataProtoOrBuilder p = viaProto ? proto : builder;
    List<ApplicationTimeoutMapProto> lists = p.getApplicationTimeoutsList();
    this.applicationTimeouts = new HashMap<ApplicationTimeoutType, Long>(lists.size());
    for (ApplicationTimeoutMapProto timeoutProto : lists) {
        this.applicationTimeouts.put(ProtoUtils.convertFromProtoFormat(timeoutProto.getApplicationTimeoutType()), timeoutProto.getTimeout());
    }
}
Also used : ApplicationStateDataProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServerResourceManagerRecoveryProtos.ApplicationStateDataProtoOrBuilder) ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) ApplicationTimeoutMapProto(org.apache.hadoop.yarn.proto.YarnProtos.ApplicationTimeoutMapProto)

Example 15 with ApplicationTimeoutType

use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.

the class RMAppLifetimeMonitor method updateApplicationTimeouts.

public void updateApplicationTimeouts(ApplicationId appId, Map<ApplicationTimeoutType, Long> timeouts) {
    for (Entry<ApplicationTimeoutType, Long> entry : timeouts.entrySet()) {
        ApplicationTimeoutType timeoutType = entry.getKey();
        RMAppToMonitor update = new RMAppToMonitor(appId, timeoutType);
        register(update, entry.getValue());
    }
}
Also used : ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType)

Aggregations

ApplicationTimeoutType (org.apache.hadoop.yarn.api.records.ApplicationTimeoutType)17 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 ApplicationTimeoutMapProto (org.apache.hadoop.yarn.proto.YarnProtos.ApplicationTimeoutMapProto)4 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)3 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)3 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)3 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)3 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)3 Test (org.junit.Test)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 UpdateApplicationTimeoutsRequest (org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsRequest)2 ApplicationTimeout (org.apache.hadoop.yarn.api.records.ApplicationTimeout)2 AppTimeoutsMapProto (org.apache.hadoop.yarn.proto.YarnProtos.AppTimeoutsMapProto)2 ApplicationUpdateTimeoutMapProto (org.apache.hadoop.yarn.proto.YarnProtos.ApplicationUpdateTimeoutMapProto)2 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)2 MemoryRMStateStore (org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore)2 ApplicationStateData (org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData)2