예제 #1
0
 private String getBaseAsyncCreateResponse(long jobId, BaseAsyncCreateCmd cmd, String objectUuid) {
   CreateCmdResponse response = new CreateCmdResponse();
   AsyncJob job = _entityMgr.findById(AsyncJob.class, jobId);
   response.setJobId(job.getUuid());
   response.setId(objectUuid);
   response.setResponseName(cmd.getCommandName());
   return ApiResponseSerializer.toSerializedString(response, cmd.getResponseType());
 }
예제 #2
0
  @SuppressWarnings("unchecked")
  private void buildAsyncListResponse(BaseListCmd command, Account account) {
    List<ResponseObject> responses = ((ListResponse) command.getResponseObject()).getResponses();
    if (responses != null && responses.size() > 0) {
      List<? extends AsyncJob> jobs = null;

      // list all jobs for ROOT admin
      if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
        jobs = _asyncMgr.findInstancePendingAsyncJobs(command.getInstanceType().toString(), null);
      } else {
        jobs =
            _asyncMgr.findInstancePendingAsyncJobs(
                command.getInstanceType().toString(), account.getId());
      }

      if (jobs.size() == 0) {
        return;
      }

      Map<String, AsyncJob> objectJobMap = new HashMap<String, AsyncJob>();
      for (AsyncJob job : jobs) {
        if (job.getInstanceId() == null) {
          continue;
        }
        String instanceUuid = ApiDBUtils.findJobInstanceUuid(job);
        objectJobMap.put(instanceUuid, job);
      }

      for (ResponseObject response : responses) {
        if (response.getObjectId() != null && objectJobMap.containsKey(response.getObjectId())) {
          AsyncJob job = objectJobMap.get(response.getObjectId());
          response.setJobId(job.getUuid());
          response.setJobStatus(job.getStatus().ordinal());
        }
      }
    }
  }