Search in sources :

Example 1 with ApplicationTimeoutType

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

the class RMAppManager method updateApplicationTimeout.

// transaction method.
public void updateApplicationTimeout(RMApp app, Map<ApplicationTimeoutType, String> newTimeoutInISO8601Format) throws YarnException {
    ApplicationId applicationId = app.getApplicationId();
    synchronized (applicationId) {
        if (app.isAppInCompletedStates()) {
            return;
        }
        Map<ApplicationTimeoutType, Long> newExpireTime = RMServerUtils.validateISO8601AndConvertToLocalTimeEpoch(newTimeoutInISO8601Format);
        SettableFuture<Object> future = SettableFuture.create();
        Map<ApplicationTimeoutType, Long> currentExpireTimeouts = app.getApplicationTimeouts();
        currentExpireTimeouts.putAll(newExpireTime);
        ApplicationStateData appState = ApplicationStateData.newInstance(app.getSubmitTime(), app.getStartTime(), app.getApplicationSubmissionContext(), app.getUser(), app.getCallerContext());
        appState.setApplicationTimeouts(currentExpireTimeouts);
        // update to state store. Though it synchronous call, update via future to
        // know any exception has been set. It is required because in non-HA mode,
        // state-store errors are skipped.
        this.rmContext.getStateStore().updateApplicationStateSynchronously(appState, false, future);
        Futures.get(future, YarnException.class);
        // update in-memory
        ((RMAppImpl) app).updateApplicationTimeout(newExpireTime);
    }
}
Also used : RMAppImpl(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl) ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) ApplicationStateData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.ApplicationStateData) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId)

Example 2 with ApplicationTimeoutType

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

the class RMServerUtils method validateISO8601AndConvertToLocalTimeEpoch.

/**
   * Validate ISO8601 format with epoch time.
   * @param timeoutsInISO8601 format
   * @return expire time in local epoch
   * @throws YarnException if given application timeout value is lesser than
   *           current time.
   */
public static Map<ApplicationTimeoutType, Long> validateISO8601AndConvertToLocalTimeEpoch(Map<ApplicationTimeoutType, String> timeoutsInISO8601) throws YarnException {
    long currentTimeMillis = clock.getTime();
    Map<ApplicationTimeoutType, Long> newApplicationTimeout = new HashMap<ApplicationTimeoutType, Long>();
    if (timeoutsInISO8601 != null) {
        for (Map.Entry<ApplicationTimeoutType, String> timeout : timeoutsInISO8601.entrySet()) {
            long expireTime = 0L;
            try {
                expireTime = Times.parseISO8601ToLocalTimeInMillis(timeout.getValue());
            } catch (ParseException ex) {
                String message = "Expire time is not in ISO8601 format. ISO8601 supported " + "format is yyyy-MM-dd'T'HH:mm:ss.SSSZ. Configured " + "timeout value is " + timeout.getValue();
                throw new YarnException(message, ex);
            }
            if (expireTime < currentTimeMillis) {
                String message = "Expire time is less than current time, current-time=" + Times.formatISO8601(currentTimeMillis) + " expire-time=" + Times.formatISO8601(expireTime);
                throw new YarnException(message);
            }
            newApplicationTimeout.put(timeout.getKey(), expireTime);
        }
    }
    return newApplicationTimeout;
}
Also used : HashMap(java.util.HashMap) ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) ParseException(java.text.ParseException) Map(java.util.Map) HashMap(java.util.HashMap) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 3 with ApplicationTimeoutType

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

the class RMWebServices method getAppTimeouts.

@GET
@Path("/apps/{appid}/timeouts")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppTimeoutsInfo getAppTimeouts(@Context HttpServletRequest hsr, @PathParam("appid") String appId) throws AuthorizationException {
    init();
    RMApp app = validateAppTimeoutRequest(hsr, appId);
    AppTimeoutsInfo timeouts = new AppTimeoutsInfo();
    Map<ApplicationTimeoutType, Long> applicationTimeouts = app.getApplicationTimeouts();
    if (applicationTimeouts.isEmpty()) {
        // If application is not set timeout, lifetime should be sent as default
        // with expiryTime=UNLIMITED and remainingTime=-1
        timeouts.add(constructAppTimeoutDao(ApplicationTimeoutType.LIFETIME, null));
    } else {
        for (Entry<ApplicationTimeoutType, Long> timeout : app.getApplicationTimeouts().entrySet()) {
            AppTimeoutInfo timeoutInfo = constructAppTimeoutDao(timeout.getKey(), timeout.getValue());
            timeouts.add(timeoutInfo);
        }
    }
    return timeouts;
}
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 4 with ApplicationTimeoutType

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

the class ApplicationReportPBImpl method addApplicationTimeouts.

private void addApplicationTimeouts() {
    maybeInitBuilder();
    builder.clearAppTimeouts();
    if (applicationTimeouts == null) {
        return;
    }
    Iterable<? extends AppTimeoutsMapProto> values = new Iterable<AppTimeoutsMapProto>() {

        @Override
        public Iterator<AppTimeoutsMapProto> iterator() {
            return new Iterator<AppTimeoutsMapProto>() {

                private Iterator<ApplicationTimeoutType> iterator = applicationTimeouts.keySet().iterator();

                @Override
                public boolean hasNext() {
                    return iterator.hasNext();
                }

                @Override
                public AppTimeoutsMapProto next() {
                    ApplicationTimeoutType key = iterator.next();
                    return AppTimeoutsMapProto.newBuilder().setApplicationTimeout(convertToProtoFormat(applicationTimeouts.get(key))).setApplicationTimeoutType(ProtoUtils.convertToProtoFormat(key)).build();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
    this.builder.addAllAppTimeouts(values);
}
Also used : ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) Iterator(java.util.Iterator) AppTimeoutsMapProto(org.apache.hadoop.yarn.proto.YarnProtos.AppTimeoutsMapProto)

Example 5 with ApplicationTimeoutType

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

the class ApplicationSubmissionContextPBImpl method initApplicationTimeout.

private void initApplicationTimeout() {
    if (this.applicationTimeouts != null) {
        return;
    }
    ApplicationSubmissionContextProtoOrBuilder 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 : ApplicationTimeoutType(org.apache.hadoop.yarn.api.records.ApplicationTimeoutType) ApplicationTimeoutMapProto(org.apache.hadoop.yarn.proto.YarnProtos.ApplicationTimeoutMapProto) ApplicationSubmissionContextProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnProtos.ApplicationSubmissionContextProtoOrBuilder)

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