Search in sources :

Example 31 with Path

use of javax.ws.rs.Path in project hadoop by apache.

the class RMWebServices method getAppActivities.

@GET
@Path("/scheduler/app-activities")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppActivitiesInfo getAppActivities(@Context HttpServletRequest hsr, @QueryParam("appId") String appId, @QueryParam("maxTime") String time) {
    YarnScheduler scheduler = rm.getRMContext().getScheduler();
    if (scheduler instanceof AbstractYarnScheduler) {
        AbstractYarnScheduler abstractYarnScheduler = (AbstractYarnScheduler) scheduler;
        ActivitiesManager activitiesManager = abstractYarnScheduler.getActivitiesManager();
        if (null == activitiesManager) {
            String errMessage = "Not Capacity Scheduler";
            return new AppActivitiesInfo(errMessage, appId);
        }
        if (appId == null) {
            String errMessage = "Must provide an application Id";
            return new AppActivitiesInfo(errMessage, null);
        }
        double maxTime = 3.0;
        if (time != null) {
            if (time.contains(".")) {
                maxTime = Double.parseDouble(time);
            } else {
                maxTime = Double.parseDouble(time + ".0");
            }
        }
        ApplicationId applicationId;
        try {
            applicationId = ApplicationId.fromString(appId);
            activitiesManager.turnOnAppActivitiesRecording(applicationId, maxTime);
            AppActivitiesInfo appActivitiesInfo = activitiesManager.getAppActivitiesInfo(applicationId);
            return appActivitiesInfo;
        } catch (Exception e) {
            String errMessage = "Cannot find application with given appId";
            return new AppActivitiesInfo(errMessage, appId);
        }
    }
    return null;
}
Also used : AbstractYarnScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler) YarnScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler) AbstractYarnScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler) ActivitiesManager(org.apache.hadoop.yarn.server.resourcemanager.scheduler.activities.ActivitiesManager) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ParseException(java.text.ParseException) AccessControlException(java.security.AccessControlException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with Path

use of javax.ws.rs.Path in project hadoop by apache.

the class RMWebServices method deleteReservation.

/**
   * Function to delete a Reservation to the RM.
   *
   * @param resContext provides information to construct
   *          the ReservationDeleteRequest
   * @param hsr the servlet request
   * @return Response containing the status code
   * @throws AuthorizationException when the user group information cannot be
   *           retrieved.
   * @throws IOException when a {@link ReservationDeleteRequest} cannot be
   *           created from the {@link ReservationDeleteRequestInfo}. This
   *           exception is also thrown on
   *           {@code ClientRMService.deleteReservation} invokation failure.
   * @throws InterruptedException if doAs action throws an InterruptedException.
   */
@POST
@Path("/reservation/delete")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteReservation(ReservationDeleteRequestInfo resContext, @Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException {
    init();
    UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
    if (callerUGI == null) {
        throw new AuthorizationException("Unable to obtain user name, " + "user not authenticated");
    }
    if (UserGroupInformation.isSecurityEnabled() && isStaticUser(callerUGI)) {
        String msg = "The default static user cannot carry out this operation.";
        return Response.status(Status.FORBIDDEN).entity(msg).build();
    }
    final ReservationDeleteRequest reservation = createReservationDeleteRequest(resContext);
    ReservationDeleteResponseInfo resRespInfo;
    try {
        resRespInfo = callerUGI.doAs(new PrivilegedExceptionAction<ReservationDeleteResponseInfo>() {

            @Override
            public ReservationDeleteResponseInfo run() throws IOException, YarnException {
                rm.getClientRMService().deleteReservation(reservation);
                return new ReservationDeleteResponseInfo();
            }
        });
    } catch (UndeclaredThrowableException ue) {
        if (ue.getCause() instanceof YarnException) {
            throw new BadRequestException(ue.getCause().getMessage());
        }
        LOG.info("Update reservation request failed", ue);
        throw ue;
    }
    return Response.status(Status.OK).entity(resRespInfo).build();
}
Also used : AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ReservationDeleteResponseInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDeleteResponseInfo) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) ReservationDeleteRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationDeleteRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 33 with Path

use of javax.ws.rs.Path in project hadoop by apache.

the class RMWebServices method getNodeToLabels.

@GET
@Path("/get-node-to-labels")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public NodeToLabelsInfo getNodeToLabels(@Context HttpServletRequest hsr) throws IOException {
    init();
    NodeToLabelsInfo ntl = new NodeToLabelsInfo();
    HashMap<String, NodeLabelsInfo> ntlMap = ntl.getNodeToLabels();
    Map<NodeId, Set<NodeLabel>> nodeIdToLabels = rm.getRMContext().getNodeLabelManager().getNodeLabelsInfo();
    for (Map.Entry<NodeId, Set<NodeLabel>> nitle : nodeIdToLabels.entrySet()) {
        List<NodeLabel> labels = new ArrayList<NodeLabel>(nitle.getValue());
        ntlMap.put(nitle.getKey().toString(), new NodeLabelsInfo(labels));
    }
    return ntl;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) NodeLabelsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ArrayList(java.util.ArrayList) NodeToLabelsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsInfo) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with Path

use of javax.ws.rs.Path 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 35 with Path

use of javax.ws.rs.Path in project hadoop by apache.

the class RMWebServices method getApps.

@GET
@Path("/apps")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppsInfo getApps(@Context HttpServletRequest hsr, @QueryParam("state") String stateQuery, @QueryParam("states") Set<String> statesQuery, @QueryParam("finalStatus") String finalStatusQuery, @QueryParam("user") String userQuery, @QueryParam("queue") String queueQuery, @QueryParam("limit") String count, @QueryParam("startedTimeBegin") String startedBegin, @QueryParam("startedTimeEnd") String startedEnd, @QueryParam("finishedTimeBegin") String finishBegin, @QueryParam("finishedTimeEnd") String finishEnd, @QueryParam("applicationTypes") Set<String> applicationTypes, @QueryParam("applicationTags") Set<String> applicationTags) {
    boolean checkCount = false;
    boolean checkStart = false;
    boolean checkEnd = false;
    boolean checkAppTypes = false;
    boolean checkAppStates = false;
    boolean checkAppTags = false;
    long countNum = 0;
    // set values suitable in case both of begin/end not specified
    long sBegin = 0;
    long sEnd = Long.MAX_VALUE;
    long fBegin = 0;
    long fEnd = Long.MAX_VALUE;
    init();
    if (count != null && !count.isEmpty()) {
        checkCount = true;
        countNum = Long.parseLong(count);
        if (countNum <= 0) {
            throw new BadRequestException("limit value must be greater then 0");
        }
    }
    if (startedBegin != null && !startedBegin.isEmpty()) {
        checkStart = true;
        sBegin = Long.parseLong(startedBegin);
        if (sBegin < 0) {
            throw new BadRequestException("startedTimeBegin must be greater than 0");
        }
    }
    if (startedEnd != null && !startedEnd.isEmpty()) {
        checkStart = true;
        sEnd = Long.parseLong(startedEnd);
        if (sEnd < 0) {
            throw new BadRequestException("startedTimeEnd must be greater than 0");
        }
    }
    if (sBegin > sEnd) {
        throw new BadRequestException("startedTimeEnd must be greater than startTimeBegin");
    }
    if (finishBegin != null && !finishBegin.isEmpty()) {
        checkEnd = true;
        fBegin = Long.parseLong(finishBegin);
        if (fBegin < 0) {
            throw new BadRequestException("finishTimeBegin must be greater than 0");
        }
    }
    if (finishEnd != null && !finishEnd.isEmpty()) {
        checkEnd = true;
        fEnd = Long.parseLong(finishEnd);
        if (fEnd < 0) {
            throw new BadRequestException("finishTimeEnd must be greater than 0");
        }
    }
    if (fBegin > fEnd) {
        throw new BadRequestException("finishTimeEnd must be greater than finishTimeBegin");
    }
    Set<String> appTypes = parseQueries(applicationTypes, false);
    if (!appTypes.isEmpty()) {
        checkAppTypes = true;
    }
    Set<String> appTags = parseQueries(applicationTags, false);
    if (!appTags.isEmpty()) {
        checkAppTags = true;
    }
    // stateQuery is deprecated.
    if (stateQuery != null && !stateQuery.isEmpty()) {
        statesQuery.add(stateQuery);
    }
    Set<String> appStates = parseQueries(statesQuery, true);
    if (!appStates.isEmpty()) {
        checkAppStates = true;
    }
    GetApplicationsRequest request = GetApplicationsRequest.newInstance();
    if (checkStart) {
        request.setStartRange(sBegin, sEnd);
    }
    if (checkEnd) {
        request.setFinishRange(fBegin, fEnd);
    }
    if (checkCount) {
        request.setLimit(countNum);
    }
    if (checkAppTypes) {
        request.setApplicationTypes(appTypes);
    }
    if (checkAppTags) {
        request.setApplicationTags(appTags);
    }
    if (checkAppStates) {
        request.setApplicationStates(appStates);
    }
    if (queueQuery != null && !queueQuery.isEmpty()) {
        ResourceScheduler rs = rm.getResourceScheduler();
        if (rs instanceof CapacityScheduler) {
            CapacityScheduler cs = (CapacityScheduler) rs;
            // validate queue exists
            try {
                cs.getQueueInfo(queueQuery, false, false);
            } catch (IOException e) {
                throw new BadRequestException(e.getMessage());
            }
        }
        Set<String> queues = new HashSet<String>(1);
        queues.add(queueQuery);
        request.setQueues(queues);
    }
    if (userQuery != null && !userQuery.isEmpty()) {
        Set<String> users = new HashSet<String>(1);
        users.add(userQuery);
        request.setUsers(users);
    }
    List<ApplicationReport> appReports = null;
    try {
        appReports = rm.getClientRMService().getApplications(request, false).getApplicationList();
    } catch (YarnException e) {
        LOG.error("Unable to retrieve apps from ClientRMService", e);
        throw new YarnRuntimeException("Unable to retrieve apps from ClientRMService", e);
    }
    final ConcurrentMap<ApplicationId, RMApp> apps = rm.getRMContext().getRMApps();
    AppsInfo allApps = new AppsInfo();
    for (ApplicationReport report : appReports) {
        RMApp rmapp = apps.get(report.getApplicationId());
        if (rmapp == null) {
            continue;
        }
        if (finalStatusQuery != null && !finalStatusQuery.isEmpty()) {
            FinalApplicationStatus.valueOf(finalStatusQuery);
            if (!rmapp.getFinalApplicationStatus().toString().equalsIgnoreCase(finalStatusQuery)) {
                continue;
            }
        }
        AppInfo app = new AppInfo(rm, rmapp, hasAccess(rmapp, hsr), WebAppUtils.getHttpSchemePrefix(conf));
        allApps.add(app);
    }
    return allApps;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) IOException(java.io.IOException) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) AppInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppInfo) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) ResourceScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) AppsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppsInfo) CapacityScheduler(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Path (javax.ws.rs.Path)1483 GET (javax.ws.rs.GET)760 Produces (javax.ws.rs.Produces)696 ApiOperation (io.swagger.annotations.ApiOperation)405 POST (javax.ws.rs.POST)378 ApiResponses (io.swagger.annotations.ApiResponses)319 Consumes (javax.ws.rs.Consumes)249 DELETE (javax.ws.rs.DELETE)205 PUT (javax.ws.rs.PUT)187 IOException (java.io.IOException)183 Response (javax.ws.rs.core.Response)157 Timed (com.codahale.metrics.annotation.Timed)134 WebApplicationException (javax.ws.rs.WebApplicationException)123 TimedResource (org.killbill.commons.metrics.TimedResource)95 HashMap (java.util.HashMap)93 URI (java.net.URI)85 ArrayList (java.util.ArrayList)79 ApiResponse (io.swagger.annotations.ApiResponse)76 AuditEvent (org.graylog2.audit.jersey.AuditEvent)74 List (java.util.List)69