RequestScheduleResourceProvider extends AbstractControllerResourceProvider { private synchronized void updateRequestSchedule (Set<RequestScheduleRequest> requests) throws AmbariException { if (requests.isEmpty()) { LOG.warn("Received an empty requests set"); return; } Clusters clusters = getManagementController().getClusters(); for (RequestScheduleRequest request : requests) { validateRequest(request); Cluster cluster; try { cluster = clusters.getCluster(request.getClusterName()); } catch (ClusterNotFoundException e) { throw new ParentObjectNotFoundException( "Attempted to add a request schedule to a cluster which doesn't " + "exist", e); } if (request.getId() == null) { throw new AmbariException("Id is a required parameter."); } RequestExecution requestExecution = cluster.getAllRequestExecutions().get(request.getId()); if (requestExecution == null) { throw new AmbariException("Request Schedule not found " + ", clusterName = " + request.getClusterName() + ", description = " + request.getDescription() + ", id = " + request.getId()); } String username = getManagementController().getAuthName(); Integer userId = getManagementController().getAuthId(); requestExecution.setBatch(request.getBatch()); requestExecution.setDescription(request.getDescription()); requestExecution.setSchedule(request.getSchedule()); if (request.getStatus() != null && isValidRequestScheduleStatus (request.getStatus())) { requestExecution.setStatus(RequestExecution.Status.valueOf(request.getStatus())); } requestExecution.setUpdateUser(username); requestExecution.setAuthenticatedUserId(userId); LOG.info("Persisting updated Request Schedule " + ", clusterName = " + request.getClusterName() + ", description = " + request.getDescription() + ", user = " + username); requestExecution.persist(); getManagementController().getExecutionScheduleManager() .updateBatchSchedule(requestExecution); } } protected  RequestScheduleResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds,
        AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate);  }
@Test public void testUpdateRequestSchedule() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class); RequestStatusResponse response = createNiceMock(RequestStatusResponse.class); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); final RequestExecution requestExecution = createNiceMock(RequestExecution.class); RequestScheduleResponse requestScheduleResponse = createNiceMock (RequestScheduleResponse.class); ExecutionScheduleManager executionScheduleManager = createNiceMock (ExecutionScheduleManager.class); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(managementController.getAuthName()).andReturn("admin").anyTimes(); expect(managementController.getAuthId()).andReturn(1).anyTimes(); expect(managementController.getExecutionScheduleManager()).andReturn (executionScheduleManager).anyTimes(); expect(requestExecution.getId()).andReturn(25L).anyTimes(); expect(requestExecution.convertToResponse()).andReturn (requestScheduleResponse).anyTimes(); expect(requestExecution.convertToResponseWithBody()).andReturn (requestScheduleResponse).anyTimes(); expect(requestScheduleResponse.getId()).andReturn(25L).anyTimes(); expect(requestScheduleResponse.getClusterName()).andReturn("Cluster100") .anyTimes(); expect(cluster.getAllRequestExecutions()).andStubAnswer(new IAnswer<Map<Long, RequestExecution>>() { @Override public Map<Long, RequestExecution> answer() throws Throwable { Map<Long, RequestExecution> requestExecutionMap = new HashMap<Long, RequestExecution>(); requestExecutionMap.put(requestExecution.getId(), requestExecution); return requestExecutionMap; } }); replay(managementController, clusters, cluster, requestExecution, response, requestScheduleResponse, executionScheduleManager); RequestScheduleResourceProvider resourceProvider = getResourceProvider (managementController); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, "Cluster100"); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_DESC_PROPERTY_ID, "some description"); properties.put(RequestScheduleResourceProvider .SCHEDULE_DAY_OF_WEEK_PROPERTY_ID, "MON"); properties.put(RequestScheduleResourceProvider .SCHEDULE_MINUTES_PROPERTY_ID, "2"); properties.put(RequestScheduleResourceProvider .SCHEDULE_END_TIME_PROPERTY_ID, "2013-11-18T14:29:29-08:00"); properties.put(RequestScheduleResourceProvider .SCHEDULE_DAYS_OF_MONTH_PROPERTY_ID, "*"); HashSet<Map<String, Object>> batch = new HashSet<Map<String, Object>>(); Map<String, Object> batchSettings = new HashMap<String, Object>(); batchSettings.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_BATCH_SEPARATION_PROPERTY_ID, "15"); Map<String, Object> batchRequests = new HashMap<String, Object>(); HashSet<Map<String, Object>> requestSet = new HashSet<Map<String, Object>>(); Map<String, Object> request1 = new HashMap<String, Object>(); Map<String, Object> request2 = new HashMap<String, Object>(); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_TYPE_PROPERTY_ID, BatchRequest.Type.PUT.name()); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_ORDER_ID_PROPERTY_ID, "20"); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_URI_PROPERTY_ID, "SomeUpdateUri"); request1.put(RequestScheduleResourceProvider .BATCH_REQUEST_BODY_PROPERTY_ID, "data1"); request2.put(RequestScheduleResourceProvider .BATCH_REQUEST_TYPE_PROPERTY_ID, BatchRequest.Type.DELETE.name()); request2.put(RequestScheduleResourceProvider .BATCH_REQUEST_ORDER_ID_PROPERTY_ID, "22"); request2.put(RequestScheduleResourceProvider .BATCH_REQUEST_URI_PROPERTY_ID, "SomeDeleteUri"); requestSet.add(request1); requestSet.add(request2); batchRequests.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_BATCH_REQUESTS_PROPERTY_ID, requestSet); batch.add(batchSettings); batch.add(batchRequests); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_BATCH_PROPERTY_ID, batch); Map<String, String> mapRequestProps = new HashMap<String, String>(); mapRequestProps.put("context", "Called from a test"); Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps); Predicate predicate = new PredicateBuilder().property (RequestScheduleResourceProvider.REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID) .equals("Cluster100").and().property(RequestScheduleResourceProvider .REQUEST_SCHEDULE_ID_PROPERTY_ID).equals(25L).toPredicate(); resourceProvider.updateResources(request, predicate); verify(managementController, clusters, cluster, requestExecution, response, requestScheduleResponse, executionScheduleManager); }