static Resource toResource(
      Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache,
      StageEntity entity,
      Set<String> requestedIds) {

    Resource resource = new ResourceImpl(Resource.Type.Stage);

    Long clusterId = entity.getClusterId();
    if (clusterId != null && !clusterId.equals(Long.valueOf(-1L))) {
      try {
        Cluster cluster = clustersProvider.get().getClusterById(clusterId);

        setResourceProperty(resource, STAGE_CLUSTER_NAME, cluster.getClusterName(), requestedIds);
      } catch (Exception e) {
        LOG.error("Can not get information for cluster " + clusterId + ".", e );
      }
    }

    if (!cache.containsKey(entity.getRequestId())) {
      cache.put(entity.getRequestId(), hostRoleCommandDAO.findAggregateCounts(entity.getRequestId()));
    }

    Map<Long, HostRoleCommandStatusSummaryDTO> summary = cache.get(entity.getRequestId());

    setResourceProperty(resource, STAGE_STAGE_ID, entity.getStageId(), requestedIds);
    setResourceProperty(resource, STAGE_REQUEST_ID, entity.getRequestId(), requestedIds);
    setResourceProperty(resource, STAGE_CONTEXT, entity.getRequestContext(), requestedIds);

    if (isPropertyRequested(STAGE_COMMAND_PARAMS, requestedIds)) {
      String value = entity.getCommandParamsStage();
      if (!StringUtils.isBlank(value)) {
        value = SecretReference.maskPasswordInPropertyMap(value);
      }
      resource.setProperty(STAGE_COMMAND_PARAMS, value);
    }

    // this property is lazy loaded in JPA; don't use it unless requested
    if (isPropertyRequested(STAGE_HOST_PARAMS, requestedIds)) {
      String value = entity.getHostParamsStage();
      if (!StringUtils.isBlank(value)) {
        value = SecretReference.maskPasswordInPropertyMap(value);
      }
      resource.setProperty(STAGE_HOST_PARAMS, value);
    }

    setResourceProperty(resource, STAGE_SKIPPABLE, entity.isSkippable(), requestedIds);

    Long startTime = Long.MAX_VALUE;
    Long endTime = 0L;
    if (summary.containsKey(entity.getStageId())) {
      startTime = summary.get(entity.getStageId()).getStartTime();
      endTime = summary.get(entity.getStageId()).getEndTime();
    }

    setResourceProperty(resource, STAGE_START_TIME, startTime, requestedIds);
    setResourceProperty(resource, STAGE_END_TIME, endTime, requestedIds);

    CalculatedStatus status;
    if (summary.isEmpty()) {
      // Delete host might have cleared all HostRoleCommands
      status = CalculatedStatus.COMPLETED;
    } else {
      status = CalculatedStatus.statusFromStageSummary(summary, Collections.singleton(entity.getStageId()));
    }

    setResourceProperty(resource, STAGE_PROGRESS_PERCENT, status.getPercent(), requestedIds);
    setResourceProperty(resource, STAGE_STATUS, status.getStatus(), requestedIds);
    setResourceProperty(resource, STAGE_DISPLAY_STATUS, status.getDisplayStatus(), requestedIds);

    return resource;
  }
Converts the {@link StageEntity} to a {@link Resource}.

@param entity        the entity to convert (not {@code null})
@param requestedIds  the properties requested (not {@code null})

@return the new resource
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java