@Test public void testGetBatchRequestResponse() throws Exception { Clusters clustersMock = createMock(Clusters.class); Cluster clusterMock = createMock(Cluster.class); Configuration configurationMock = createNiceMock(Configuration.class); ExecutionScheduler executionSchedulerMock = createMock(ExecutionScheduler.class); InternalTokenStorage tokenStorageMock = createMock(InternalTokenStorage.class); ActionDBAccessor actionDBAccessorMock = createMock(ActionDBAccessor.class); Gson gson = new Gson(); long requestId = 5L; String clusterName = "mycluster"; String apiUri = "api/v1/clusters/mycluster/requests/5"; Capture<String> uriCapture = EasyMock.newCapture(); BatchRequestResponse batchRequestResponse = new BatchRequestResponse(); batchRequestResponse.setStatus(HostRoleStatus.IN_PROGRESS.toString()); batchRequestResponse.setRequestId(requestId); batchRequestResponse.setReturnCode(202); EasyMock.expect(configurationMock.getApiSSLAuthentication()).andReturn(Boolean.FALSE); EasyMock.replay(configurationMock); ExecutionScheduleManager scheduleManager = createMockBuilder(ExecutionScheduleManager.class). withConstructor(configurationMock, executionSchedulerMock, tokenStorageMock, clustersMock, actionDBAccessorMock, gson). addMockedMethods("performApiGetRequest").createNiceMock(); expect(scheduleManager.performApiGetRequest(capture(uriCapture), eq(true))).andReturn(batchRequestResponse).once(); replay(clusterMock, clustersMock, executionSchedulerMock, tokenStorageMock, scheduleManager); scheduleManager.getBatchRequestResponse(requestId, clusterName); verify(clusterMock, clustersMock, configurationMock, executionSchedulerMock, tokenStorageMock, scheduleManager); assertEquals(apiUri, uriCapture.getValue()); }
public BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName) throws AmbariException { StrBuilder sb = new StrBuilder(); sb.append(DEFAULT_API_PATH) .append("/clusters/") .append(clusterName) .append("/requests/") .append(requestId); return performApiGetRequest(sb.toString(), true); }
ExecutionScheduleManager { public BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName) throws AmbariException { StrBuilder sb = new StrBuilder(); sb.append(DEFAULT_API_PATH) .append("/clusters/") .append(clusterName) .append("/requests/") .append(requestId); return performApiGetRequest(sb.toString(), true); } }
ExecutionScheduleManager { public BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName) throws AmbariException { StrBuilder sb = new StrBuilder(); sb.append(DEFAULT_API_PATH) .append("/clusters/") .append(clusterName) .append("/requests/") .append(requestId); return performApiGetRequest(sb.toString(), true); } @Inject  ExecutionScheduleManager(Configuration configuration,
                                  ExecutionScheduler executionScheduler,
                                  InternalTokenStorage tokenStorage,
                                  Clusters clusters,
                                  ActionDBAccessor actionDBAccessor,
                                  Gson gson); }
ExecutionScheduleManager { public BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName) throws AmbariException { StrBuilder sb = new StrBuilder(); sb.append(DEFAULT_API_PATH) .append("/clusters/") .append(clusterName) .append("/requests/") .append(requestId); return performApiGetRequest(sb.toString(), true); } @Inject  ExecutionScheduleManager(Configuration configuration,
                                  ExecutionScheduler executionScheduler,
                                  InternalTokenStorage tokenStorage,
                                  Clusters clusters,
                                  ActionDBAccessor actionDBAccessor,
                                  Gson gson); void start(); void stop(); boolean isSchedulerAvailable(); void scheduleJob(Trigger trigger); boolean continueOnMisfire(JobExecutionContext jobExecutionContext); void scheduleBatch(RequestExecution requestExecution); void updateBatchSchedule(RequestExecution requestExecution); void validateSchedule(Schedule schedule); void deleteAllJobs(RequestExecution requestExecution); Long executeBatchRequest(long executionId,
                                  long batchId,
                                  String clusterName); BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName); void updateBatchRequest(long executionId, long batchId, String clusterName,
                                 BatchRequestResponse batchRequestResponse,
                                 boolean statusOnly); boolean hasToleranceThresholdExceeded(Long executionId,
      String clusterName, Map<String, Integer> taskCounts); void finalizeBatch(long executionId, String clusterName); }
ExecutionScheduleManager { public BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName) throws AmbariException { StrBuilder sb = new StrBuilder(); sb.append(DEFAULT_API_PATH) .append("/clusters/") .append(clusterName) .append("/requests/") .append(requestId); return performApiGetRequest(sb.toString(), true); } @Inject  ExecutionScheduleManager(Configuration configuration,
                                  ExecutionScheduler executionScheduler,
                                  InternalTokenStorage tokenStorage,
                                  Clusters clusters,
                                  ActionDBAccessor actionDBAccessor,
                                  Gson gson); void start(); void stop(); boolean isSchedulerAvailable(); void scheduleJob(Trigger trigger); boolean continueOnMisfire(JobExecutionContext jobExecutionContext); void scheduleBatch(RequestExecution requestExecution); void updateBatchSchedule(RequestExecution requestExecution); void validateSchedule(Schedule schedule); void deleteAllJobs(RequestExecution requestExecution); Long executeBatchRequest(long executionId,
                                  long batchId,
                                  String clusterName); BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName); void updateBatchRequest(long executionId, long batchId, String clusterName,
                                 BatchRequestResponse batchRequestResponse,
                                 boolean statusOnly); boolean hasToleranceThresholdExceeded(Long executionId,
      String clusterName, Map<String, Integer> taskCounts); void finalizeBatch(long executionId, String clusterName); static final String USER_ID_HEADER; }