Ejemplo n.º 1
0
  /**
   * parameter: 'orderId' The id of the order to search for approvals parameter: 'approvalStatus'
   * The status for the approval. parameter: 'tenantId' The id of the tenant (if not the current
   * tenant)
   *
   * @return Return a list of matching approvals or an empty list if no match was found.
   */
  @Override
  protected SearchResults getOtherSearchResults(
      Map<String, List<String>> parameters, boolean authorized) {

    StorageOSUser user = getUserFromContext();
    String tenantId = user.getTenantId();
    if (parameters.containsKey(SearchConstants.TENANT_ID_PARAM)) {
      tenantId = parameters.get(SearchConstants.TENANT_ID_PARAM).get(0);
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), user);

    if (!parameters.containsKey(SearchConstants.ORDER_ID_PARAM)
        && !parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
      throw APIException.badRequests.invalidParameterSearchMissingParameter(
          getResourceClass().getName(),
          SearchConstants.ORDER_ID_PARAM + " or " + SearchConstants.APPROVAL_STATUS_PARAM);
    }

    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM)
        && parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
      throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(
          getResourceClass().getName(),
          SearchConstants.ORDER_ID_PARAM,
          SearchConstants.APPROVAL_STATUS_PARAM);
    }

    List<ApprovalRequest> approvals = Lists.newArrayList();
    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM)) {
      String orderId = parameters.get(SearchConstants.ORDER_ID_PARAM).get(0);
      ArgValidator.checkFieldNotEmpty(orderId, SearchConstants.ORDER_ID_PARAM);
      approvals = approvalManager.findApprovalsByOrderId(uri(orderId));
    } else if (parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
      String approvalStatus = parameters.get(SearchConstants.APPROVAL_STATUS_PARAM).get(0);
      ArgValidator.checkFieldNotEmpty(approvalStatus, SearchConstants.APPROVAL_STATUS_PARAM);
      approvals =
          approvalManager.findApprovalsByStatus(
              uri(tenantId), ApprovalStatus.valueOf(approvalStatus));
    }

    ResRepFilter<SearchResultResourceRep> resRepFilter =
        (ResRepFilter<SearchResultResourceRep>)
            getPermissionFilter(getUserFromContext(), _permissionsHelper);

    List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
    for (ApprovalRequest approval : approvals) {
      RestLinkRep selfLink =
          new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), approval.getId()));
      SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
      searchResultResourceRep.setId(approval.getId());
      searchResultResourceRep.setLink(selfLink);
      if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
        searchResultResourceReps.add(searchResultResourceRep);
      }
    }

    SearchResults result = new SearchResults();
    result.setResource(searchResultResourceReps);
    return result;
  }
  /**
   * check to see if the individual nodes of one vdc are visible from another
   *
   * @param checkParam
   * @return
   */
  @POST
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  @Path("/nodecheck")
  public VdcNodeCheckResponse checkNodeConnections(
      VdcNodeCheckParam checkParam, @HeaderParam("X-Forwarded-For") String clientIp) {
    List<VdcConfig> vdcList = checkParam.getVirtualDataCenters();

    log.info("checking nodes for vdcs {} ...", getVdcIds(vdcList));

    if (service.getId().endsWith("standalone")) {
      throw GeoException.fatals.remoteVDCWrongStandaloneInstall();
    }

    ArgValidator.checkFieldNotEmpty(vdcList, "vdc");
    VirtualDataCenter localVdc = VdcUtil.getLocalVdc();
    if (localVdc == null) {
      throw GeoException.fatals.failedToFindLocalVDC();
    }

    return toVdcNodeCheckResponse(localVdc, helper.areNodesReachable(vdcList, false));
  }